1

I'm reading an XLSX (Microsoft Excel XML file) using the Excel Data Reader from http://exceldatareader.codeplex.com/ and I getting some unexpected results.

The following code outputs data from multiple tabs

var reader = Excel.ExcelReaderFactory.CreateOpenXmlReader(uploadFile.InputStream);
while (reader.Read())
{
    System.Diagnostics.Debug.WriteLine(reader.FieldCount );
    for (int i = 0; i < reader.FieldCount; i++)
    {
        System.Diagnostics.Debug.Write(reader[i] + "*");
    }
    System.Diagnostics.Debug.WriteLine("\n~\n");
}

On a single line, I can get data from 3 or more tabs.

I would expect this to loop through and show all of the contents of the first tab and only the first tab.

What am I missing?

Update: It appears that the above code does work fine if there is only 1 tab in the excel file. This may just be a bug with this library. Has anyone else used this library to parse excel files with multiple tabs?

Thanks

1
  • Also an unexpected result is when we try to read an excel with values that use comma (,) as decimal point. It converts 3,5 to 35. :-O Commented Oct 30, 2013 at 20:10

2 Answers 2

2

OK, so my reply is extremely late with reference to this question, but if its any help try encapsulating your code in a reader.NextResult() block. This works the same way as when you parse through multiple DataTable objects within a DataSet.

Additionally, this approach has a very small memory footprint as opposed to the reader.AsDataSet() method, which hogs a lot of memory even for workbooks as small as 20MBs

eg

var reader = Excel.ExcelReaderFactory.CreateOpenXmlReader(uploadFile.InputStream);
do
{
    while (reader.Read())
    {
        System.Diagnostics.Debug.WriteLine(reader.FieldCount );
        for (int i = 0; i < reader.FieldCount; i++)
        {
            System.Diagnostics.Debug.Write(reader[i] + "*");
        }
        System.Diagnostics.Debug.WriteLine("\n~\n");
    }
}while(reader.NextResult());
Sign up to request clarification or add additional context in comments.

Comments

-1

Which is why I am using NPOI. I have tried several other Excel readers, this one actually worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.