How to add new column names to a newly created excel file

I need to create a excel file . I need to add different column names to that file. After that I need to use write range activity to write datatable to excel file…
My question is how to add column names to a new created blank excel file.

Anyone please help me with the answer…

@rifnanahas You need to first read that new Excel File, so you can get it as a Datatable, then you can use Add Data Column Activity

2 Likes

Hi
Being a blank excel we won’t get any datatable out of it
So rather reading a blank excel file
We can directly create a datatable with BUILD DATATABLE activity with n number of columns we want

Then we can add records with ADD DATAROW activity and then write back to the same blank excel file with WRITE RANGE activity

Cheers @rifnanahas

1 Like

Another option without using a datatable is to open one Excel file using Excel Application Scope. If you require a format or template in the origin sheet (sheet to be copied) this can also come in handy. After that use Copy Sheet activity and provide destination path and sheet name of the target excel file. With this, you have full control on what sheetname to use. You can use a For Each loop to automate the sheet creation in the target file.

To populate the contents of the target excel file and sheet, just open the file and use Write Range.

1 Like

can you please explain more deeply how to use ADD DATAROW activity

1 Like

Fine
Add Datarow activity has two ways of giving input
One is like array or values (which is equal to number of columns) and another one is as a DataRow variable

So for the first we can pass the value as array like this
{“value1”,”value2”,…”valuen”} and here the number of elements we mention must b equal to number of columns

And in another way it’s DataRow variable that is of type System.Data.DataRow
We usually see row variable in FOR EACH ROW activity right…it’s of that type variable only
So that can be either passed as input

And input datatable to which we want to add the row

Cheers @rifnanahas

1 Like

Here is my file. Before writing data table EmpSort to excel (i.e before using WRITE RANGE activity), I need to add three column names to my excel file.How is it possible?
sample.xaml (7.0 KB)

AddDataRow.xaml (6.2 KB)
you can have a look at this let me if this is what you are looking for
cheers @rifnanahas

1 Like

Not this one…My issue is how to add column names to excel before using write range activity

By using Assign activity with

dataTable .Columns( “old_ColumnName”) .ColumnName= “new_ColumnName”

1 Like

My datatable doesn’t have old column name…Can we assign a column name to a column by its index…

yes you can

1 Like

Here you go with a xaml
hope its resolved
addcol.zip (2.3 KB)

Kindly try this and let know for any queries or clarification
Cheers @rifnanahas

1 Like

can please write the statement

Datatablevar.Columns(0).ColumnName = “newColumnName”

0 is your index of the column to be renamed.

1 Like

Thank you…

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