From 8795189d599e28a4c37b2655b83a0f109acd86b8 Mon Sep 17 00:00:00 2001 From: juvenile Date: Mon, 13 May 2024 16:59:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(worksheet):=20=E5=8A=A0=E8=BD=BD=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E8=A7=A3=E6=9E=90=E6=9C=89=E6=95=88=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=20=E5=92=8C=E9=80=89=E4=B8=AD=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=A0=BC=20=E6=8C=89Ctrl-A=E7=9A=84=E6=95=88?= =?UTF-8?q?=E6=9E=9C=E5=A4=A7=E4=BD=93=E7=9B=B8=E5=90=8C=20(Resolve=20vali?= =?UTF-8?q?d=20regions=20when=20loading=20data=20Similar=20to=20selecting?= =?UTF-8?q?=20a=20cell=20The=20effect=20of=20pressing=20Ctrl-A=20is=20roug?= =?UTF-8?q?hly=20the=20same)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QXlsx/header/xlsxworksheet.h | 3 +++ QXlsx/header/xlsxworksheet_p.h | 3 +++ QXlsx/source/xlsxworksheet.cpp | 26 ++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) 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