Write range with headers Datatable

Hello friends,
@rkelchuri, @arivu96, @Rammohan91, @balupad14, @Florent_Salendres, @vvaidya, @Palaniyappan, @loginerror, @MAHESH1, @Manjuts90


I need to wite a datatable which is empty but I need to maintain the headers of the datatable at the top.
How to write the headers at the top also if the datatable is empty?
Thank you,
Cami

You should use build data table activity. Then you can use write range activity which add headers property enabled. That could work i guess.

1 Like

@CamiCat Get Count Of the table if Zero then Use IF else and Write the table you created using Build DataTable else the original table

Hi cami
Whether you have a datatable obtained by any means with or without data like either obtained from data scrapping or using build datatable activity, whenever we use a WRITE RANGE activity we need to enable ADD HEADERS property and in the range mention as “A1” so that the headers will be included and also the will be included at the top that is the first row of the excel at all situations

Hope this would help you
Cheers @CamiCat

Hi @CamiCat,

If you are using Excel - Write Range :
Check Add Headers in the Write Range Activity

If you are using Workbook - Write Range Activity :
If you want to write the DataTable even if it is Empty follow below simple Method.

  • Build a Data Table with your required Columns and Add first row with same column names
  • Don’t use Add Headers in Write Range Activity while writing to Workbook.

Note : This is for Writing Headers even DataTable is empty. if you want DataTable row count , It will give one extra row count, As we added Header as row.

Solution : Add Headers.xaml (6.6 KB)

Add%20Headers

Thanks.!
Ramprasad

1 Like

Thank you so much @Ramprasad.
I’ll try and let you know as soon as possible.
Cami :slight_smile:

May I know why do we need to add the header again in the first row of the datatable explicitly
Rather we can just do with a simple check box ADD HEADERS
Because this is fine if we have a single data entry but what if there are two or more than five
We won’t be able to explicitly add a row same as headers in all the datatable as a first row

If ADD HEADERS is enabled it will automatically the first row as headers right @CamiCat

Kindly elaborate that @Ramprasad

Hi @Palaniyappan,

Yes, You are correct , If we are using Write Range with Excel Application Scope, it will Add Headers even there is no Data in the DataTable. In the Workbook Write Range Activity , if there is no data in the DataTable , it will not add headers.

Thanks.!
Ramprasad

Thank you so much @Palaniyappan,
is it also possible to add an empty row (how to initialize an empty row) and then wirte range in the Excel?
Thank you so much,
Cami :slight_smile:

1 Like

Yah of course
In add data row activity mention this in the datarow property
Yourdatatablename.NewRow and in the datatable mention the datatable name
The we can pass that as input to write range activity
Cheers @CamiCat

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