Quantcast
Channel: Excel Data Reader - Read Excel files in .NET
Viewing all 448 articles
Browse latest View live

Commented Unassigned: Inaccurate column count causes data to be missed. [12605]

$
0
0
Discussion [https://exceldatareader.codeplex.com/discussions/474291](https://exceldatareader.codeplex.com/discussions/474291)

I am trying to read in a large amount of data using your wonderful tool, which is ideal.
The problem is that the xlsx file in question has presumably been generated by a tool, as unless you manually open and then save and close the file, the ExcelDataReader will only read in the first column.

There are in fact 13 columns, but the first 2 rows are merged.

Having looked at the source code and stepped through, I can see that while reading the rows in, the array to hold the values is 1 in size, so all the following values are not saved, even though they are read in.

Any help would be much appreciated. :)
Comments: ** Comment from web user: TMVector **

The problem appears to lie in that the dimensions of the spreadsheet are not recorded properly in the dimension tag. It simply reads 'A1' instead of 'A1:M11791'

To fix this, I added an else block to the statement that checks if the column value will fit it the array:
```
...

int rowIndex = int.Parse(_xmlReader.GetAttribute(XlsxWorksheet.A_r));
if (rowIndex != (_depth + 1))
{
_emptyRowCount = rowIndex - _depth - 1;
}


//If the row number is larger than specified, change dimensions
if (sheet.Dimension.LastRow < rowIndex)
sheet.Dimension.LastRow = rowIndex;

...
```

I also added an if statement after the row index is read to modify the row dimension.
```
...

int rowIndex = int.Parse(_xmlReader.GetAttribute(XlsxWorksheet.A_r));
if (rowIndex != (_depth + 1))
{
_emptyRowCount = rowIndex - _depth - 1;
}

// * This is the new code *
//If the row number is larger than specified, change dimensions
if (sheet.Dimension.LastRow < rowIndex)
sheet.Dimension.LastRow = rowIndex;

...

```


Commented Unassigned: Inaccurate column count causes data to be missed. [12605]

$
0
0
Discussion [https://exceldatareader.codeplex.com/discussions/474291](https://exceldatareader.codeplex.com/discussions/474291)

I am trying to read in a large amount of data using your wonderful tool, which is ideal.
The problem is that the xlsx file in question has presumably been generated by a tool, as unless you manually open and then save and close the file, the ExcelDataReader will only read in the first column.

There are in fact 13 columns, but the first 2 rows are merged.

Having looked at the source code and stepped through, I can see that while reading the rows in, the array to hold the values is 1 in size, so all the following values are not saved, even though they are read in.

Any help would be much appreciated. :)
Comments: ** Comment from web user: TMVector **

I apologize. I mis-pasted the first code sample, and automatically pressed Ctrl-S before I had proof-read.

Here is the modified code to modify the column dimension
```
...

if (col <= _cellsValues.Length)
_cellsValues[col - 1] = o;
else
{
//If the column number is larger than the dimension given at the top of the sheet, then we need to expand dynamically
sheet.Dimension.LastCol = col;

Array.Resize(ref _cellsValues, sheet.ColumnsCount);

_cellsValues[col - 1] = o;
}

...
```

Commented Unassigned: Cannot find central directory [11965]

$
0
0
I am using the last stable release of this version. It was working just fine until a few weeks ago. Now I am constantly getting the error "Cannot find central directory". The error is being thrown at the line :

zipFile = new ZipFile(fileStream);

Method : public bool Extract(Stream fileStream)
File : ZipWorker.cs

It used to read both excel 2010 and excel 2003. Now it reads neither. throws different errors, but with excel 2003 (xls files), it throws the error as above. with excel 2010 (xlsx) it doesnt even get this far.

I have enclosed the file that I am working with.

What could be the problem on this ?
Comments: ** Comment from web user: showkath **

Hi,

I am also facing same issue when try to read xls .ExcelReaderFactory.CreateOpenXmlReader(excelStream)
__Exception__ : Cannot find central directory.

Regards,
Showkath.

New Post: ExcelReaderFactory.CreateBinaryReader(stream) is returning an empty DataTable

New Post: Working Example

$
0
0
I love this tool, as by converting Excel file of any type into DataTables in a DataSet, Excel becomes transparent to the user. In my application, this makes life easy.
I made a short working C# demo that I post here.

Make a new Project, add a DataGridView and run the demo with either xls or xlsx file.
using System.Data;
using System.Windows.Forms;
using System.IO;
using Excel;

namespace ExcelDataReader
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            displayDataGrid(getDataSet());
        }

        public DataSet dataSet = new DataSet();

        public DataSet getDataSet()
        {
            // Get the Excel file and convert to dataset 
            OpenFileDialog fileDialog = new OpenFileDialog();
            DialogResult result = fileDialog.ShowDialog();
            FileStream stream = File.Open(fileDialog.FileName, FileMode.Open, FileAccess.Read);
            if (fileDialog.FileName.EndsWith("xls"))
                dataSet = readExcel2003(stream);
            if (fileDialog.FileName.EndsWith("xlsx"))
                dataSet = readExcelXML(stream);
            return dataSet;
        }

        public DataSet readExcelXML(FileStream stream)
        {
            //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            dataSet = excelReader.AsDataSet();
            excelReader.Close();
            return dataSet;
        }

        public DataSet readExcel2003(FileStream stream)
        {
            //1. Reading from a binary Excel file ('97-2003 format; *.xls)
            IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            dataSet = excelReader.AsDataSet();
            excelReader.Close();
            return dataSet;
        }

        public void displayDataGrid(DataSet dataSet)
        {
            dataGridView1.DataSource = dataSet.Tables[1];
            dataGridView1.Show();

        }
    }
}

Commented Issue: Exponential problem when load a .xlsx [11773]

$
0
0
I try to load a .xlsx and the decimal number like 2345,12 look like 2,345123637347E+16, i need fix that faster, what can i do?
Comments: ** Comment from web user: larbou **

Yes, indeed, i got the same problem when i try to load my worksheet when i use a coma for decimal separator.
When the software unzip the content of ../xl/worksheets/sheet1.xml the value are like this 321.521 and when iopen my xlsx file the values has coma decimal separator like 321,521.
I has debud the process and it try to parse the string (321.521) to double but your regional setting don't allow to convert this string to double with a dot decimal separator.

exactly the code is :

double number;
object o = _xmlReader.Value;
if (double.TryParse(o.ToString(), out number))
o = number;
....

i have try to shortcut the double parsing, but i got bad number format
for ex: 231.99 became 321.9899999999992

i don't have solution for the moment... i search to solve this ASAP.

other else if i convert my file to XLS format, it work correctly.

New Post: Problem: Excel\ExcelBinaryReader.cs missing

$
0
0
Hi,
While the program was running OK, I occasionally got error for xls files
"The file 'c:\development\eapidemo\third-party\ExcelDataReader\ExcelDataReader\Excel\ExcelBinaryReader.cs' does not exist"
The generated DataSet is 'null'.
It will work OK for xlsx.
Now I have that issue all the times: Can not run for xls.
I naturally installed the two reader's dll (and, as I wrote, got it to work!), but I was not sure where I was supposed to place the Excel.pdb file. Could this cause the problem?.

I could not locate the missing file or folderfrom the error elsewhere on my computer (C#, VS2010 Express, Win7 with Excel).

How come it does work at times, but then stops?
What am I supposed to do about it?
Thanks

New Post: Neither stream 'Workbook' nor 'Book' was found in file

$
0
0
Hi,

I am having the same problem, runs OK with xlsx, fails occasionally with xls , but I could not solve it with either solution:
  1. (mmleoni): Did not make a difference
  2. (petemunnings): The ExcelReaderFactory.CreateBinaryReader(stream, ReadOption.Loose);
    does not accept any second parameter (ReadOption or other).
    How did you get it to accept the new parameter?
Any idea?
Thanks.

New Post: Neither stream 'Workbook' nor 'Book' was found in file

$
0
0
Its an overload on that Method. Do you have the latest version?
public static IExcelDataReader CreateBinaryReader(Stream fileStream)
{
  IExcelDataReader excelDataReader = (IExcelDataReader) new ExcelBinaryReader();
  excelDataReader.Initialize(fileStream);
  return excelDataReader;
}

public static IExcelDataReader CreateBinaryReader(Stream fileStream, ReadOption option)
{
  IExcelDataReader excelDataReader = (IExcelDataReader) new ExcelBinaryReader(option);
  excelDataReader.Initialize(fileStream);
  return excelDataReader;
}

New Post: Neither stream 'Workbook' nor 'Book' was found in file

$
0
0
Hi,
Thanks petemunnings.
Yes, I understand it is an overload on the CreateBinaryReader method, but I do not seem to have that overload.
I downloaded the (said-to-be) latest version from the Download, which is 2.1 dated January 2013.
Is there a newer version I can download that has that overload, or is there a workaround to the ReadOption.Lose ?
(My original problem was errors opening the xls binaries)

samtal

New Post: Neither stream 'Workbook' nor 'Book' was found in file

$
0
0
You can download the source code and create the overload yourself. I think that's what I did

Source code checked in, #86976

Closed Unassigned: Xlsx with multiple sheets has no first row on last sheet [12271]

$
0
0
This is because an internal value is not cleared on on NextResultSet.
Comments: Resolved with changeset 86976.

Closed Unassigned: Xlsx exported from Google Docs have no data [12253]

$
0
0
Export and xlsx from Google spreadsheets. It appears with no data in ExcelDataReader.

After investigation it appears that there is no dimension element in the xlsx from Google.

We will have to decide what the default should be if dimensions not specified.
Comments: Resolved with changeset 86976.

Commented Unassigned: Inaccurate column count causes data to be missed. [12605]

$
0
0
Discussion [https://exceldatareader.codeplex.com/discussions/474291](https://exceldatareader.codeplex.com/discussions/474291)

I am trying to read in a large amount of data using your wonderful tool, which is ideal.
The problem is that the xlsx file in question has presumably been generated by a tool, as unless you manually open and then save and close the file, the ExcelDataReader will only read in the first column.

There are in fact 13 columns, but the first 2 rows are merged.

Having looked at the source code and stepped through, I can see that while reading the rows in, the array to hold the values is 1 in size, so all the following values are not saved, even though they are read in.

Any help would be much appreciated. :)
Comments: ** Comment from web user: Ian1971 **

I have just committed a fix for something very similar to this which was occuring on files with missing dimensions. It would be great to know if this also fixes your issue.


Source code checked in, #86978

$
0
0
I've added a trap for the fat table reading zero for the next sector. I don't think this is allowed anyway, and this stops the infinite loop issue

Closed Issue: Corrupt XLS file goes into infinite loop [12556]

$
0
0
If I try to open a corrupt file, it goes into infinite loop, and then OutOfMemoryException. The only way is to kill the process.

```
FileStream stream = File.Open("c:\\temp\\corrupt.xls", FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
```

2nd line will go into infinite loop.

corrupt.xls is attached.

Appreciated any help. Please let me know if need more information. Thanks.
Comments: Resolved with changeset 86978: I've added a trap for the fat table reading zero for the next sector. I don't think this is allowed anyway, and this stops the infinite loop issue

Commented Issue: Exponential problem when load a .xlsx [11773]

$
0
0
I try to load a .xlsx and the decimal number like 2345,12 look like 2,345123637347E+16, i need fix that faster, what can i do?
Comments: ** Comment from web user: Ian1971 **

I just looked at this and I think it has already been fixed. Can you get the latest code from the repository?

Reviewed: ExcelDataReader v2.1 (jan 07, 2014)

$
0
0
Rated 5 Stars (out of 5) - Works perfectly for me: open a 2013 xslx and read all it's data. Thanks a million!

New Post: In source code Core/ReferenceHelper.cs and SeekErrorMemoryStream.cs are missing

$
0
0
Hi,
I downloaded latest source code version. When I try to compile the solution those files Core/ReferenceHelper.cs and SeekErrorMemoryStream.cs are missing.
Is it a source control problem? or I did something wrong?
Thanks

Andrea
Viewing all 448 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>