DataTable to HTML using Assign Activity

Hello,

Here is the solution for converting DataTable variable into HTML table.
By this you can avoid adding new dependencies to your project or implementing long workflows to get data in HTML table format.

Create a String variable (HTMLBodyStr) and assign below expression to it. Replace TestDT variable with your Datatable Variable

HTMLBodyStr="<table border=2><tr><td>"+String.Join("</td><td>",TestDt.Columns.Cast(Of DataColumn).Select(Function (x) x.ColumnName).ToArray)+"</td></tr>"+
"<tr>"+String.Join("</tr><tr>",(From x In TestDt.AsEnumerable
Let cells="<td>"+String.Join("</td><td>",x.ItemArray)+"</td>"
Select cells).ToArray)+"</tr>"

You can find the same in this link

18 Likes

Hi @poorna_nayak07,

That is a cool little snippet requiring zero dependencies.

Quite useful for people looking to embed html tables in emails.
Thanks for sharing.

I will soon try it out on a TDD generator workflow.

So great solution.
I newy to this. So how can I change headers to be bold?

Hi @JavRR ,

Glad to know that it is useful to you
You could try below expression to get what you wanted to.

HTMLBodyStr="<table border=2><b><tr><td>"+String.Join("</td><td>",TestDt.Columns.Cast(Of DataColumn).Select(Function (x) x.ColumnName).ToArray)+"</td></tr></b>"+
"<tr>"+String.Join("</tr><tr>",(From x In TestDt.AsEnumerable
Let cells="<td>"+String.Join("</td><td>",x.ItemArray)+"</td>"
Select cells).ToArray)+"</tr>"

Thanks,

1 Like

Hi, Thanks for the guide.
I got an error. Do you have a xaml file to compare?

Hi @RPA_Canada,

The reason for the issue you are facing is because of an extra assignment operation inside assign activity.

Please refer above picture and remove highlighted part from assign activity

Thanks

Hi this was very helpfull for me .
Please how can I modify that code so i could change the color of a column

Hi @kawtar.ettayarssouti

You may need HTML inline styling to change the color of the column.
Below I have added the link for related articles please look into it.

can we specify the data we want to assign ? like by column there are 3 specific keywords and we need to specify it by 2 of the keyword

@kh4d Welcome to the UiPath Forum

It is a bit difficult to understand your requirements with the above message. Could you briefly explain maybe with examples? (like input data and expected output)