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

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;

...

```


Viewing all articles
Browse latest Browse all 448

Trending Articles



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