I have an excel file and i want to read only the header of that excel file.
The problem is the header range is not always constant so cant specify the range while doing read range.
Question: how i can read only the header of the excel file without reading the entire excel data and store into datatable.
Use read range workbook activity to read the excel, in the properties of the read range workbook activity check the add headers option. Then it will read the data with headers and store in a datatable variable called Input_dt.
After read range use the assign activity and create a datatable variable called headers_dt
- Assign -> headers_dt = Input_dt.Clone()
Check the below workflow for better understanding,
Correct…this can be done but i dont want to read the entire excel file and store it into datatable and than get the header…can this be done without reading to datatable first?
No…i dont want to delete anything. Let me break the requirement:
I am having a very large excel file foe which i am using oledb connection as it is large.
2.but there is a small requirement. I want to just read the header of this big excel file for which header range in not constant.
How to just get the header name of this excel file without deleting anything or reading the entire file to datatable
Try liek this…this will give all column names as array…you can use to create the datatable with those columns, Can be used inside use excel file
(From dc In Excel.Sheet("SheetName").DataTableValue.Columns.Cast(Of System.Data.DataColumn) Select dc.ColumnName).ToArray()
another way is you can get column count and then read using range which reads only the columns filled and only column namesExcel.Sheet("SheetName").Range("A1:A" + Excel.Sheet("SheetName").GetNumberOfColumns.ToString)
Can you give us more details? Are there blank rows before the headers? Blank columns?
It sounds like you’ll have to read the entire sheet from A1 (with use headers unchecked), then use some logic to determine which row and column the headers start in.
Using “read row” activity with range as “A1”. This is only giving me the firts row which is header and not blank row.
Store this result in variable called “Getcolname”.
Use assign activity and do this
ColumnIndex(int32) = Getcolname.Count