How to get the columns count in excel with out using Data table

I need to compare A1 with B1 and C1 and other column names also in excel…if any two column names are equal… i need to modify the duplicate column name to other name…if any one have the solution help me…

Hi @sindhura506

Is there any particular reason why you wouldn’t want to load your Excel file into a Data Table?

  1. Load Excel into Data Table
  2. Do the comparisons
  3. Modify the names of other columns by using the Write Cell activity

It looks to me like the best approach.

@loginerror Hi,

If excel has duplicate column names, we cant read that excel then how we can load it into datatable?

Correct me if i am wrong?

if we use Data table we will get duplicate column name exception…

Indeed, but there are ways out of it :slight_smile:
You could load it without considering the first row as column headers (uncheck it in the Read Range activity).

This will load the column names as a normal row in Data Table, while assigning internal column names as Column0, Column1, and so on :slight_smile:

If you output it to the console, you will see something like this:

for an input like this:

1 Like

@sindhura506 Not sure useful or not check attached zip file for reference (7.9 KB)

i need headers also…if i uncheck headers based on that headers i’m getting values of particular cell

You will also get the values of your headers copied into the Data Table, but as normal values in the first row. You can then act accordingly.

@sindhura506 Find the attached workflow it will solve ur problem mostly.

expNew.xaml (16.0 KB)

Reference excel sheet is attached below, You can find the output in Sheet2.

new.xlsx (8.7 KB)

1 Like

H @Manjuts90
In the mentioned code, what is the initial value of variable count as i am not able to understand the condition “count<dt.Columns.Count-1”

Instead of using row.item(colname) you can n use row.item(datatable.rows(0). item(index))

@pruthvisiddhartha count variable initial value is 0.