Skip to content

Commit

Permalink
XLSX: do not emit error on <row> without 'r' attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 12, 2024
1 parent b9f419d commit e7e1d75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Binary file not shown.
13 changes: 13 additions & 0 deletions autotest/ogr/ogr_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,16 @@ def test_ogr_xlsx_read_xml_prefix():
f = lyr.GetNextFeature()
assert f["Col1"] == "foo"
assert f["Col2"] == "bar"


###############################################################################
# Test reading a XLSX file with <row> without "r" attribute


def test_ogr_xlsx_read_row_without_r_attribute():

ds = ogr.Open("data/xlsx/row_without_r_attribute.xlsx")
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
assert f["ID"] == 1
assert f["NAME"] == "TEST123"
20 changes: 14 additions & 6 deletions ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,14 +816,22 @@ void OGRXLSXDataSource::startElementTable(const char *pszNameIn,
apoCurLineValues.clear();
apoCurLineTypes.clear();

int nNewCurLine = atoi(GetAttributeValue(ppszAttr, "r", "0"));
if (nNewCurLine <= 0)
int nNewCurLine;
if (const char *pszR = GetAttributeValue(ppszAttr, "r", nullptr))
{
CPLError(CE_Failure, CPLE_AppDefined, "Invalid row: %d",
nNewCurLine);
return;
nNewCurLine = atoi(pszR);
if (nNewCurLine <= 0)
{
CPLError(CE_Failure, CPLE_AppDefined, "Invalid row: %d",
nNewCurLine);
return;
}
nNewCurLine--;
}
else
{
nNewCurLine = nCurLine;
}
nNewCurLine--;
const int nFields = std::max(
static_cast<int>(apoFirstLineValues.size()),
poCurLayer != nullptr ? poCurLayer->GetLayerDefn()->GetFieldCount()
Expand Down

0 comments on commit e7e1d75

Please sign in to comment.