How to read particularly 55th to 100th column name in excel

Hi everyone am trying to read the 55th to 100th column name in excel if i use this syntax
String strCabinet = dt.columns(55).toString() i can able to get only 55th column name but i have to get columns from 55th to 100 and write it in one application for this i have to assigned to one variable then only i can increment and get all required value while passing the variable am getting error like
" ‘Public ReadOnly Default Property Item(index As Integer) As System.Data.DataColumn’: Not most specific. C:\Users\tdivya\Documents\UiPath\ASU\Main.xaml"

Kindly help me out in this.

You want those all column names in one variable??
If yes
then


Assign----
Colname is String datattype
ColName=Join(Row.ItemArray," , ")

Yes I have to write that inside the application one by one ,

Hi,

Try with the following,

dt.Columns.Cast(Of DataColumn)().[Select](Function(x) x.ColumnName).ToList()

This will return all the Column names into a List(Of String) named as listColumns

Then use the below code to get the columns from 55 - 100 in a list string.
here N value should be 45 if you have to get it from 55 to 100.

listColumns.Skip(Math.Max(0, listColumns.Count() - N)).ToList

what i have to replace x with?

[quote=“sarathi125, post:4, topic:160412”]
[Select](Function(x) x.ColumnName)
[/quote] what it does?

Nothing needs to be changed if you have a datatable named dt and list of string variable as listcolumns.

For results create another list of string and assign it

Its Linq Lambda expression, check this link for more details on it.
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions

Thanks for solution is that applies to get 1 to 55 column name ?

usually the List.Skip will accept integer number and it will skip those items while reading it.

listColumns.Skip(Math.Max(0, listColumns.Count() - N)).ToList

So here Max will return 0 or listColumnsCount - 55 - In your case it is 100 - 45 = 55
hence it will come now as listColumns.Skip(55), so you will get the last 45 items in your list.
If you want the first 55 items, then

listColumns.Take(55)

If you need the second 10 items, then

listColumns.Skip(10).Take(10)

Hope this answers your question.

1 Like

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