Excel 2007 (xlsx) support?

Oct 15, 2009 at 2:27 PM
Edited Oct 15, 2009 at 2:45 PM

Thanks for the great component!

Does the latest version ( supports Excel 2007  (xlsx) files?
It works well for my Excel 97-2003 files, but returns nothing for Excel 2007 (DataSet with 0 tables).

Here's the code:


Dim stream As FileStream = File.Open(strFileName, FileMode.Open, FileAccess.Read)
Dim excelReader As IExcelDataReader
If strFileName.Substring(strFileName.LastIndexOf("."c) + 1).ToLower = "xls" Then
excelReader = ExcelReaderFactory.CreateBinaryReader(stream)
ElseIf strFileName.Substring(strFileName.LastIndexOf("."c) + 1).ToLower = "xlsx" Then
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream)
End If

Dim ds As DataSet = excelReader.AsDataSet
For Each dt As DataTable In ds.Tables
For Each row As DataRow In dt.Rows
Dim res As String = String.Empty
For i As Int32 = 0 To row.ItemArray.Length - 1
res &=  String.Format("{0}", row.ItemArray(i))

' do something with res




Any Excel 2007 working code sample (vb or c#) would be highly appreciated.

Thanks in advance!


UPDATE: The problem seems to derive from an Excel 2007 file with a single worksheet. I ran this code with another Excel 2007 file, which has 3 worksheets (2 are empty), and it works fine. Any suggestions on how to load an Excel 2007 file with only 1 worksheet?