How do I extract the tabular data from the email body? If the email contains a structured HTML table, what activities or techniques should I use to convert it into a Data Table format in UiPath? After extracting the table data, how can I write it to an Excel file?
1. Extract the Email Body
- Use the
Get Outlook Mail Messages
orGet IMAP Mail Messages
activity to retrieve the email.
- Set the appropriate filters to identify the target email (e.g., subject, sender).
- Loop through the retrieved emails using a
For Each
activity.
2. Extract the HTML Content
- Use the
MailMessage.Body
property to get the email body.
3. Parse the HTML Table
To extract the table data:
- Use the
UiPath.WebAPI.Activities.HtmlAgilityPack
package or a similar method to parse the HTML. - Alternatively:
- Use the
Matches
activity with a regex pattern to locate the table structure. - Use string manipulation to extract the table rows and columns.
For a simpler approach, consider using the Extract Structured Data
activity if the table is rendered in a browser during email preview.
4. Convert HTML Table to DataTable
- Use the
Html to DataTable
activity from theUiPathTeam.DataTable.Activities
package.- Install the package via Manage Packages.
- Pass the HTML content to the activity to directly extract a
DataTable
.
5. Write the DataTable to Excel
- Use the
Write Range
activity from the UiPath.Excel.Activities package.
- Provide the file path and sheet name.
- Pass the extracted
DataTable
as input.
- Ensure the Excel Application Scope is used if interacting with
.xls
or.xlsx
files.
Thanks