I have .xsl file created in Excel 2010. When loading the file with CreateBinaryReader i get all DataTables and rows within them. But when open that file in OpenOffice and Save it without any modifications and then load it again with CreateBinaryReader all DataTables created have one row less then the file created with Excel 2010.
What could be the problem?
Comments: ** Comment from web user: DanielRousseau **
There is indeed a bug that drops the first row of Open Office .xls files when column names are NOT read from the first row.
The problem is in the method readWholeWorkSheetNoIndex() in ExcelBinaryReader.cs, where
"justAddedColumns = true;" is in the wrong spot. It needs to be moved from right after "triggerCreateColumns = false;" to right after the first for loop since it is only relevant if the first row consist of column names. The method with the fix is shown below.
private void readWholeWorkSheetNoIndex(bool triggerCreateColumns, DataTable table)
{
while (Read())
{
if (m_depth == m_maxRow) break;
bool justAddedColumns = false;
//DataTable columns
if (triggerCreateColumns)
{
if (_isFirstRowAsColumnNames || (_isFirstRowAsColumnNames && m_maxRow == 1))
{
for (int i = 0; i < m_maxCol; i++)
{
if (m_cellsValues[i] != null && m_cellsValues[i].ToString().Length > 0)
Helpers.AddColumnHandleDuplicate(table, m_cellsValues[i].ToString());
else
Helpers.AddColumnHandleDuplicate(table, string.Concat(COLUMN, i));
}
justAddedColumns = true;
}
else
{
for (int i = 0; i < m_maxCol; i++)
{
table.Columns.Add(null, typeof(Object));
}
}
triggerCreateColumns = false;
table.BeginLoadData();
}
if (!justAddedColumns && m_depth > 0 && !(_isFirstRowAsColumnNames && m_maxRow == 1))
{
table.Rows.Add(m_cellsValues);
}
}
if (m_depth > 0 && !(_isFirstRowAsColumnNames && m_maxRow == 1))
{
table.Rows.Add(m_cellsValues);
}
}