How to write only column names of datatable to excel when datatable has no data

Hello everyone

I want to display the column headers of the datatable into excel when the datatable has no rows

When i try this using write range the excel is blank with no column headers eventhough i checked add headers property

Did you mention the range in the activity?

In write range i mentioned as A1

Just remove it and try

Not worked

Hi @Amulya_A

When you do not have rows and if you need header then first check if rows are there and if they are not then use a add datarow and add the header row data using the below in the add datarow and then write to excel without headers

(From dc In dt.Columns.Cast(Of System.Data.DataColumn) Select dc.ColumnName).ToArray()

This will give column names as array add this array in add data row. Dt is the datatable you have

Cheers

Hi,

In this case, we need to create datatable to write header as the following, for example.
This sample will work, even if column type is not String or Object.

Sequence.xaml (8.1 KB)

Regards,

Will try this .thank you

1 Like

Will try this solution.Thank you

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