I am currently evaluating ASPOSE.cells to see if it is a viable solution for our .NET needs. I have successfully exported(imported) an Excel spreadsheet into a DataTable, and then DataSet, but I have one issue. I cannot find a directive to have the first row of the DataTable be the actual column names. When using MSJet or ACE drivers, you can use HDR=Yes to accomplish this, and the ExcelDataReader on CodePlex offers IsFirstRowAsColumnNames = True. Is there a way to accomplish this in ASPOSE?
You may use the ExportTableOptions.ExportColumnName property to assign the columns header as column names in the exported DataTable. Please check the following code snippet for better elaboration.
C#
var book = new Workbook(“D:/temp/book1.xlsx”);
var sheet = book.Worksheets[0];
var cells = sheet.Cells;
var table = cells.ExportDataTable(0, 0, cells.MaxDataRow, cells.MaxDataColumn + 1, new ExportTableOptions() { ExportColumnName = true});
Please feel free to write back in case you face any difficulty.
It’s good to know that the provided solution helped with your requirement. Please feel free to write back in case you need our further assistance with Aspose APIs.
Well, in ExportDataTable method, the first row will always be taken as column names when you specify ExportColumnName Boolean parameter to true. This is common scenario as column names will always be the top row for a certain dataset. So, your code will not work as per your needs if you want to accomplish your custom oriented requirements (which is not general) where the column names won’t come from very first record (10th indexed position in your case).
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.