Write the values based on the column name in write cell activity

Can we use write cell activity to write the values based on the column name ?

I have a excel where i had to perform write cell .but the column index can change frequently .

Hi @tharani.natarajan

In that case, you could use the following expression to determine the column index before proceeding with the Write Cell actions:

columnIndex = dataTable.Columns.IndexOf("ColumnName")

Here, ‘columnIndex’ variable is of the type ‘Int32’

Hope this helps,
Best Regards.

Thanks ,lets say i m looking for MailId column to write a value in it .It is in B column .But based on this logic it would give me column index as 2 .How to use this 2 inside the write cell activity

Hi @tharani.natarajan ,

Assuming that you have read the Data as a Datatable in Excel sheet, we can check with the below to convert Column Index to Column Letter :

columnLetter = UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(DT.Columns.IndexOf("MailId")+1)

Here, DT is the Datatable variable and columnLetter is a String variable.

2 Likes

@tharani.natarajan

Once you get the column index number, you can easily convert that to the corresponding letter by using this simple expression:

letter = Chr(Cint(columnIndex)+1 + 64).ToString

Hope this helps,
Best Regards.

1 Like

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