Unable to write headers of datatable into an excel without erasing previous data

Hi All,

I have a data table in which three columns are created, now I need to print those three columns into an excel.

I had checked add headers option in Write Cell Activity.
Moreover, I had not added any data to the data table.
I don’t want to add empty “Add Data Row” Activity because it is erasing previous value stored in excel(i.e., A2 cell data is erased).
Could anyone please suggest me to solve this issue. @Palaniyappan

Hi @Shivaraju,

1.Are you using Write range activity?
2.If you are using Write range and checked add headers those headers should replace the previous present headers of your sheet.


1 Like

Hi @Shivaraju,
Try using it as below.
Read your current excel along with the headers (if your excel has column names) else read without column names. for ex. dtExcelRead

while i<dtYourDataTable (to copy columns names).columns.count

So, it will replace the current column name of the excel with column names of your datatabale.
now overwrite the same excel with write range along with add headers the excel data with dtExcelRead (data would be same but along with header names).

Hope this will work for you.

1 Like

If we want to change the header name alone then get the datatable variable named dt with READ RANGE Activity and there enable add headers property
So now we will be having the datatable with header in it
—now use a assign activity like this to change the header name
dt.Columns(“yourcolumnname”).Columnname = “your new name”
Similar for other columns as well
Once this is done use WRITE RANGE ACTIVITY and mention the same datatable dt as input and as it has the new column name enable ADD HEADERS property so that it will write the same excel with new column headers without deleting the previous data

Cheers @Shivaraju

1 Like