Skip to content

Commit

Permalink
Merge pull request #311 from alexagr/fix-empty-columns
Browse files Browse the repository at this point in the history
- fix parsing of worksheets that lack column number / have invalid dimension
  • Loading branch information
j2doll authored Dec 18, 2023
2 parents a98a964 + cfe9447 commit 0c8a176
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 0c8a176

Please sign in to comment.