Add datarow to an existing excel

Hi,
i would like to know how can i add a new row with new data to an existing excel ?
i use read range to read the data table,
i create a dataRow = DataTable.NewRow
i count the number of row in it,
i assign several variable to the new row,
i use add row

And know how can i add that row at the end of DataTable?
i used append activity but it seems to copy the existing DT, copy it and paste next to it.

thanks

Hi,
Use add data row activity to add the new dat row to the end of the datatable.
Let us know if this helps.

And then you can use write range to write the datatable back to the excel

Regards,
Pavan H

@grish,

Please find the attached workflow.

DataRow.xaml (7.8 KB)

that’s what i did but how can i write the new data table without rewriting on the old one ?
i just need to add the new row to the old excel file

Hi,
you have the datatable with you, and the add data row activity will add the new row from the end of the datatable rows, And main thing is columns should be of same type for the new datarow that you like to add to the existing table

Regards,
Pavan H

you’re saying that i need to keep the excel open? i was just using excel app scope

Hi, from excel application scope you will get the data into datatable using read range activity once you get the data inside the datatable then you can do add datarow activity, the add data row activity will add new row at the end of the table not to excel, once you have completed adding rows to data table write the data back to excel using write range.

Regards,
Pavan H

suppose i am working with an open excel file, how can i write on it ? is there a way to get the sheet ?

1 Like

There is a simple way to add/append a single datarow to an excel file. Most of the activities accepts DataTable (write range, append range), so if you would like to append a single row to an excel you can pass it as a parameter of this activity using:

(new DataRow() {YOURROWNAME}).CopyToDataTable

5 Likes