Add two column in last

hi
Actually my requirement is like this. I am having one excel in which I have to add two column in last. Column name “Prize” and “Owner”.
But my existing column range will be dynamic. So first we need to get last column and then add above two column. I am attaching the excel.
We have to add new column after column “Name” but “Name” column would be dynamic sometime its in “C” place or sometime in “D”
How to identify that?
test.xlsx (11.0 KB)

@sshitol UiPath Go ! BalaReva EasyExcel Activities - #11 by balupad14

1 Like

@sangeethaneelavannan1 ,
is it possible to find without BALAREVA activity.

HI @sshitol

Try like this

  • First use Read range and read the data and store them in the datatable DT.
  • DT.Columns.Count will get you the count of the column
  • Use the below expression to get the column letter
Uipath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(Dt.Columns.Count)

This will get you the Alphabet like
if your column count 2
the expression exactly get you “B”

and then you can chose the cell number like

“B”+“2”

Hope this helps!

Regards
Sudharsan

Hai…

Try this way…

Column_Count = DataTable_Variable.columns.count
Column_Count = Column_Count -1

In assign create variable to store that alphabet
chr(65 + column_Count)

For ex,
If your column count is 4 means
Its going to degrees one , so its 3

Now, 3 is your existing final column index

When we use chr(65+column_count)
Chr(65+3) output is D

Now your last existing column is D

Then you can add column_count + 1… You get next column of E to write your next data

Hi @Sudharsan_Ka ,

Actually my requirement is like this. I am having one excel in which I have to add two column in last. Column name “Prize” and “Owner”.
But my existing column range will be dynamic. So first we need to get last column and then add above two column. I am attaching the excel.
We have to add new column after column “Name” but “Name” column would be dynamic sometime its in “C” place or sometime in “D”
test.xlsx (11.0 KB)

@sumitha_karthik ,

pls check my requirement

Hello @sshitol

You can use Insert Column acitvity. Then you can set the relative column option.

Thanks

@sshitol

Do as below
image

Thanks

@sshitol

If you want to insert the two new columns after Name means you can use modern insert column activity

image

You need to give the details like where to add “after” and in the relative column “Name”
image

In column header you need to give “Prize”
image

Next another one insert column
where to add “after” and in the relative column “Prize”
In column header you need to give “Owner”

To enable modern activities checkout this link

hope this helps!

Regards
Sudharsan

It doesn’t matter where the columns are. After using Read Range to read the file into a datatable, you can reference the columns by the column name, not position. Add Data Column will just add the new columns onto the end, no matter how many columns there are. Then you can just Write Range to a new Excel file and delete the old one.

I dont see where in activity. We are using old version.

Is there any other way

Checkout this and enable the modern first and follow the same @sshitol

Does your excel cells have formula? If not, then you can try the below -

  1. Read range the excel data into a data table
  2. Add 2 new data columns at the end
  3. Do any logical operations to fill up the columns
  4. Write range the updated data to the same excel sheet at A1; which overwrites the existing data with 2 new columns

Hi @sshitol

First make a Read Range and then take two Add Data Column activity.
Add your columns one by one.
Finally make a Write Range on the same sheet and same range.
Make sure the Write Range has its AddHeader property checked.

As your test file has the Other column names at row 6, the read and write range need to be initiated at A6

This will give you a final sheet like this:

Let us know if it works for you.

For your convenience, here is the workflow file:
AddTwoColum.zip (19.8 KB)

Cheers

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