column names not getting set in datatable

Jun 13, 2011 at 12:25 AM

Hi All,

I am having hard time to set the column names in a DataTable. I am following the example given in the homepage and setting "IsFirstRowAsColumnNames" property to true, but still I am getting column names as Column0, Column1 etc.

I am not sure how to fix this. Currently I am using ExcelReaderFactory.CreateBinaryReader(stream) to create reader.

Any pointers would greatly help.



Jun 13, 2011 at 4:01 AM

Well.. looks like the problem with the excel file itself. File I was using was created using the previous version of excel. I created a new file using excel 2007 and everything works great.



Mar 6, 2012 at 5:41 PM

Posting this in case it helps someone else...

I ran into this issue recently. But the file that was failing had been created in Excel 2007. The xls file created in 2007 was very simple, and in the code I had the IsFirstRowAsColumnNames property set to true. I got it to work by copying and repopulating a file created using Crystal Reports. But this was a major annoyance. I have to use the XLS format because I already found the XLSX reader in this library to be buggy (it was randomly ignoring some columns).

I tried recreating the file that worked in Excel 2007, making it match *exactly* to the good file (same data, same formats, etc.). But it still wouldn't work. The file sizes didn't match though, which indicated they still weren't an exact match. Looking at the files in plain text editors indicates that there are additional headers present in the good file. Maybe this was the cause of the problem.