From cfe944701e622d9a6c410ddd862cd53abdc8db92 Mon Sep 17 00:00:00 2001 From: Alex Agranov Date: Fri, 20 Oct 2023 01:34:54 +0300 Subject: [PATCH] fix worksheet parsing of worsheets that lack dimension / column number --- QXlsx/source/xlsxworksheet.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index 32a79e5..36144eb 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -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()) { @@ -2305,6 +2308,12 @@ 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 { @@ -2312,6 +2321,11 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) 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; @@ -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)