Copy table with the same format into the email body

Hi Team,

I have data exported from my dashboard into a CSV sheet and there is no format and I need to send this table through the Body email but I need to formatted in good shape so any idea?

Hello @omar_ismail, Try this:

  1. Read the CSV Data: Use the “Read CSV” activity in UiPath to read the data from your CSV file. This activity will provide you with a DataTable that contains the data from the CSV.
  2. Format the DataTable: Depending on your desired table format, you can manipulate the DataTable to make it more presentable. For example, you can remove unnecessary columns, sort the data, or apply conditional formatting to highlight specific values.
  3. Create an HTML Table: Use the DataTable data to construct an HTML table. You can use the “Build Data Table” activity in StudioX to create the HTML table as a string. Alternatively, if you are using Studio, you can use the “Invoke Code” activity to write custom code to create the HTML table.
  4. Compose Email: Use the “Send Outlook Mail” activity in StudioX or the “Send SMTP Mail Message” activity in Studio to send the email. In the body of the email, use the HTML table created in the previous step to present the formatted data.

Hi @omar_ismail

  1. Read the table data from a source (e.g., Excel, CSV, database) and store it in a DataTable variable.
  2. Create an email message using the “Send Outlook Mail Message” or “Send SMTP Mail Message” activity, depending on your email provider.
  3. In the body of the email message, insert an HTML table that matches the format of the source table.
  4. Convert the DataTable to an HTML table format. You can use the following code snippet to accomplish this:
htmlTable = "<table>"
For Each row In dataTable.Rows
    htmlTable = htmlTable + "<tr>"
    For Each col In dataTable.Columns
        htmlTable = htmlTable + "<td>" + row(col).ToString + "</td>"
    htmlTable = htmlTable + "</tr>"
htmlTable = htmlTable + "</table>"

Insert the HTML table into the email body by assigning the htmlTable variable to the body property of the email activity.

Hope it works!!

Here buddy, theres an activity which do this automatically

Hi @omar_ismail

To format the data from a CSV file and send it in a well-formatted table through the body of an email using UiPath, you can follow these steps:

  1. Read the CSV file: Use the “Read CSV” activity to read the data from the CSV file and store it in a DataTable variable. Specify the file path of the CSV file in the activity’s properties.

  2. Format the DataTable: Depending on your desired table format, you can perform various operations on the DataTable to format it accordingly. For example, you can rename columns, rearrange the order of columns, apply formatting to specific columns, or perform calculations if needed.

  3. Convert DataTable to HTML table: To convert the formatted DataTable into an HTML table, you can use the following custom code in an “Assign” activity:

htmlTable = "<table border='1'>"
htmlTable += "<tr>"
For Each col As DataColumn In dataTable.Columns
    htmlTable += "<th>" + col.ColumnName + "</th>"
htmlTable += "</tr>"

For Each row As DataRow In dataTable.Rows
    htmlTable += "<tr>"
    For Each col As DataColumn In dataTable.Columns
        htmlTable += "<td>" + row(col).ToString() + "</td>"
    htmlTable += "</tr>"

htmlTable += "</table>"

Make sure to replace dataTable with the name of your DataTable variable.

  1. Send email with formatted table: Use the “Send Outlook Mail Message” activity or any other email activity of your choice to send the email. In the body of the email, provide the htmlTable variable containing the HTML-formatted table.

This way, the data from the CSV file will be formatted into an HTML table and sent as the body of the email.

Hope it helps!!

Hi @omar_ismail ,

Could you check the below post :

We should be able to convert the Datatable to HTML Table with Simple formatting the Linq Expression provides. We can then alter as needed the expression for adding more styles or font changes.

Let us know if you were able to implement the above method.

i can’t get number 2 and 3 if you can elaborate