web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Split text in power au...
Power Automate
Answered

Split text in power automate

(0) ShareShare
ReportReport
Posted on by 108

Hi everyone,

 

 How to transfer this kind of data from Outlook to Excel table? Please help me, thanks.

 

Email Body:

rrrradfafwgvafv_0-1716105680940.png

 

Excel table:

rrrradfafwgvafv_1-1716105680942.png

 

 

also 1 more question, is it only available to transfer data to excel table? what if i do not create a table in excel, is it still another way to transfer data to excel?

I have the same question (0)
  • AK88 Profile Picture
    453 on at

    Hi @rrrradfafwgvafv , 

     

    Kindly find and try the below  steps:

    1. Read the email body

    2. Create a data table with required columns

    3. loop the items and store the values in to data table

    4. Update Data table to the new excel. 

     

     

    thanks,

     

  • Verified answer
    CU16071609-1 Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    Try the below approach: 

    Deenuji_0-1716133575815.png

     

     

    Code:

     

    Outlook.Launch Instance=> OutlookInstance
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    Outlook.RetrieveEmailMessages.RetrieveEmails Instance: OutlookInstance Account: $'''Deenu@microsoft.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.All MarkAsRead: False ReadBodyAsHtml: False SubjectContains: $'''Class Marks''' Messages=> RetrievedEmails
    SET EmailBody TO RetrievedEmails[0].Body
    SET DataTable TO { ^['Class', 'Student Number', 'Student Name', 'Gender'] }
    Text.SplitText.Split Text: EmailBody StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TextList
    LOOP FOREACH CurrentItem IN TextList
     IF IsNotEmpty(CurrentItem) THEN
     Text.SplitText.SplitWithDelimiter Text: CurrentItem CustomDelimiter: $'''|''' IsRegEx: False Result=> Tablelist
     Variables.AddRowToDataTable.AppendRowToDataTable DataTable: DataTable RowToAdd: Tablelist
     END
    END
    Variables.DeleteRowFromDataTable DataTable: DataTable RowIndex: 0
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DataTable.ColumnHeadersRow Column: $'''A''' Row: 1
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DataTable Column: $'''A''' Row: 2
    Excel.SaveExcel.SaveAs Instance: ExcelInstance DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''C:\\Boot\\Classmark.xlsx'''

     

     

    Input:

    Deenuji_2-1716133721706.png

     

     

    Output:

    Deenuji_1-1716133679631.png

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀 

  • rrrradfafwgvafv Profile Picture
    108 on at

    Hi Sir,

    this is the outcome, not what i wanted.

    rrrradfafwgvafv_0-1716133689798.png

     

  • Verified answer
    CU16071609-1 Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    I've revised my response once more. Kindly review the response above again.

  • rrrradfafwgvafv Profile Picture
    108 on at

    it works now, many many thanks.

  • rrrradfafwgvafv Profile Picture
    108 on at

    Hi Sir,

     

    But what if my data is huge, it is around 10000 rows of data. Is there any faster way to transfer the data instead of keeping inserting a row? can i just directly paste the split data to excel?

    Capture.PNG

  • Verified answer
    CU16071609-1 Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    Go with .Net scripting language:

    Deenuji_0-1716137989687.png

     

    Code:

    Outlook.Launch Instance=> OutlookInstance
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    Outlook.RetrieveEmailMessages.RetrieveEmails Instance: OutlookInstance Account: $'''Deenu@microsoft.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.All MarkAsRead: False ReadBodyAsHtml: False SubjectContains: $'''Class Marks''' Messages=> RetrievedEmails
    SET EmailBody TO RetrievedEmails[0].Body
    SET DataTable TO { ^['Class', 'Student Number', 'Student Name', 'Gender'] }
    Scripting.RunDotNetScript Language: System.DotNetActionLanguageType.CSharp Script: $''' // Split the email body into lines
     string[] textList = EmailBody.Split(new string[] { \"\\n\" }, StringSplitOptions.RemoveEmptyEntries);
    
     // Process each line
     foreach (string currentItem in textList)
     {
     if (!string.IsNullOrWhiteSpace(currentItem))
     {
     // Split the line using custom delimiter |
     string[] tableList = currentItem.Split(new string[] { \"|\" }, StringSplitOptions.None);
    
     // Add the row to DataTable
     DataRow newRow = dataTable.NewRow();
     newRow.ItemArray = tableList;
     dataTable.Rows.Add(newRow);
     }
     }''' @'name:EmailBody': EmailBody @'type:EmailBody': $'''String''' @'direction:EmailBody': $'''In''' @'name:dataTable': DataTable @'type:dataTable': $'''Datatable''' @'direction:dataTable': $'''InOut''' @dataTable=> DataTable
    Variables.DeleteRowFromDataTable DataTable: DataTable RowIndex: 0
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DataTable.ColumnHeadersRow Column: $'''A''' Row: 1
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DataTable Column: $'''A''' Row: 2
    Excel.SaveExcel.SaveAs Instance: ExcelInstance DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''C:\\Boot\\Classmark.xlsx'''

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Verified answer
    CU16071609-1 Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    The above .Net code based solution very much faster than PAD based solution.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 252 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard