How to paste datatable in word without Column0, Column1

Hi,

I have to paste the datatable to word without headers. I read range the table without header (unchecked) and when I use activity Insert datatable into word document it still ads the headers.
This is the table:
image

I read it without headers, and still it inserts the table like this in word:

I tried using remove data row with row index 0 but it only removes the row aa,11 and not the Column0 and Column1

Hi @markosc
datatables always need the headers,

in case if you still wish to delete headers
Try to use read range activity, in this activity you can read whole datatable and if you go through the properties of read range activity you can see AddHeaders checkbox. just uncheck that checkbox.

pass output data table variable in write range correct.
In write range properties uncheck AddHeaders.

Try this:
Uncheck “AddHeaders” property in write range

Hi @markosc,

Check if the below link helps you, by this you can remove headers.

Thanks

I am not writing it in new excel, but in WORD DOC

Hi @markosc ,

To Perform this, we actually would need some external c# or vb.net code. But If we know that the Values of a Single Row would not be the same, then We can make the first row of the Datatables as the Column Headers first. Then Remove the First row.

This way the Rows are Intact while the Header Names/Column Names are removed.

Take a Look at the below Implementation :

We get the First Row Values in the form of an Object Array.

drArray = DT.Rows(0).ItemArray.ToArray

drArray is a Variable of Type Array of Object.

Now we would require to Change the Column Names of the Datatable, which we can perform using For Each Activity as shown below :

Notice, I have also declared i as the index varaible of For Each.

Lastly We can remove the First Row from the Datatable using the Remove Data Row Activity in the below way :

image

But this method should only be used when there is certainty that we have different values in the First Row, Else while renaming the Columns there would be an Exception Generated.

We can tackle Problems like that too generally later if found.

Hi @markosc please find below sample code
OutputWithoutHeaders.xaml (9.2 KB)
if there are project dependencies , please download package (uipath.word.axtivities) from manage packages

I have done some testing and the only time Insert DataTable in Document ignore the headers is when your column names are named Column1, Column2, Column3, etc. This explains why it works to insert data table without headers from Build Data Table and Generate Data Table activities since the columns are named correctly. Unfortunately for you the Read Range activity starts the column name from zero (i.e Column0, Column1, Column2).

To solve your issue, either rename the columns or use Generate Data Table to build a data table with correct column names.

You can for example use a For loop to rename the columns:

ForEach i in Enumerable.Range(0, dt1.Columns.Count).Reverse
{
    dt1.Columns(i).ColumnName = "Column" + (i+1).ToString
}

image

I’ve solved this by selecting the table with hotkeys and paste it to word with word activity paste as link.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.