diff --git a/QXlsx/header/xlsxworksheet.h b/QXlsx/header/xlsxworksheet.h index 7c9232a8..2cd56628 100644 --- a/QXlsx/header/xlsxworksheet.h +++ b/QXlsx/header/xlsxworksheet.h @@ -192,6 +192,9 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet private: void saveToXmlFile(QIODevice *device) const override; bool loadFromXmlFile(QIODevice *device) override; + +public: + const QList &editRegion() const; }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxworksheet_p.h b/QXlsx/header/xlsxworksheet_p.h index 30f08463..680d8850 100644 --- a/QXlsx/header/xlsxworksheet_p.h +++ b/QXlsx/header/xlsxworksheet_p.h @@ -243,6 +243,9 @@ class WorksheetPrivate : public AbstractSheetPrivate private: static double calculateColWidth(int characters); + +private: + QList editRegions; }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index 36144eb6..4f7dca42 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -2321,8 +2321,7 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) QXmlStreamAttributes attributes = reader.attributes(); QString r = attributes.value(QLatin1String("r")).toString(); CellReference pos(r); - if (r.isEmpty()) - { + if (r.isEmpty()) { pos.setRow(row_num); pos.setColumn(++col_num); } @@ -2444,6 +2443,23 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) } cellTable[pos.row()][pos.column()] = cell; + + if (cell->value().isNull()) { + continue; + } + + if (editRegions.empty()) { + editRegions << CellRange{pos, pos}; + } else { + auto &cellRange = editRegions.last(); + if (cellRange.lastRow() == pos.row() && cellRange.lastColumn() < pos.column()) { + cellRange.setLastColumn(pos.column()); + } + + if (pos.row() - cellRange.lastRow() == 1) { + cellRange.setLastRow(pos.row()); + } + } } } } @@ -2910,4 +2926,10 @@ QVector Worksheet::getFullCells(int *maxRow, int *maxCol) return ret; } +const QList &Worksheet::editRegion() const +{ + Q_D(const Worksheet); + return d->editRegions; +} + QT_END_NAMESPACE_XLSX