Skip to content

Commit

Permalink
fix worksheet parsing of worsheets that lack dimension / column number
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Agranov committed Oct 19, 2023
1 parent fbf2c37 commit cfe9447
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions QXlsx/source/xlsxworksheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,9 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)

Q_ASSERT(reader.name() == QLatin1String("sheetData"));

int row_num = 0;
int col_num = 0;

while (!reader.atEnd() && !(reader.name() == QLatin1String("sheetData") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
if (reader.readNextStartElement()) {
Expand Down Expand Up @@ -2305,13 +2308,24 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
}
}

if (attributes.hasAttribute(QLatin1String("r")))
row_num = attributes.value(QLatin1String("r")).toInt();
else
++row_num;
col_num = 0;

} else if (reader.name() == QLatin1String("c")) // Cell
{

// Cell
QXmlStreamAttributes attributes = reader.attributes();
QString r = attributes.value(QLatin1String("r")).toString();
CellReference pos(r);
if (r.isEmpty())
{
pos.setRow(row_num);
pos.setColumn(++col_num);
}

// get format
Format format;
Expand Down Expand Up @@ -2433,6 +2447,12 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
}
}
}

if (dimension.lastRow() < row_num)
dimension.setLastRow(row_num);

if (dimension.lastColumn() < col_num)
dimension.setLastColumn(col_num);
}

void WorksheetPrivate::loadXmlColumnsInfo(QXmlStreamReader &reader)
Expand Down

0 comments on commit cfe9447

Please sign in to comment.