From d014ab38622c48de39ed20e06806269a7f1da642 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti Date: Mon, 4 Sep 2023 00:40:44 -0300 Subject: [PATCH] Write sheetFormatProps --- QXlsx/header/xlsxutility_p.h | 1 + QXlsx/header/xlsxworksheet_p.h | 7 ------- QXlsx/source/xlsxutility.cpp | 5 +++++ QXlsx/source/xlsxworksheet.cpp | 34 ++++++++++++---------------------- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/QXlsx/header/xlsxutility_p.h b/QXlsx/header/xlsxutility_p.h index e7423e79..a1aebd7d 100644 --- a/QXlsx/header/xlsxutility_p.h +++ b/QXlsx/header/xlsxutility_p.h @@ -21,6 +21,7 @@ QT_BEGIN_NAMESPACE_XLSX class CellReference; bool parseXsdBoolean(const QString &value, bool defaultValue = false); +QString xsdBoolean(bool value); QStringList splitPath(const QString &path); QString getRelFilePath(const QString &filePath); diff --git a/QXlsx/header/xlsxworksheet_p.h b/QXlsx/header/xlsxworksheet_p.h index b7210b71..30f08463 100644 --- a/QXlsx/header/xlsxworksheet_p.h +++ b/QXlsx/header/xlsxworksheet_p.h @@ -197,18 +197,11 @@ class WorksheetPrivate : public AbstractSheetPrivate QMap sharedFormulaMap; // shared formula map CellRange dimension; - int previous_row; mutable QMap row_spans; QMap row_sizes; QMap col_sizes; - int outline_row_level; - int outline_col_level; - - int default_row_height; - bool default_row_zeroed; - // pagesetup and print settings add by liufeijin 20181028, liufeijin QString PpaperSize; QString Pscale; diff --git a/QXlsx/source/xlsxutility.cpp b/QXlsx/source/xlsxutility.cpp index d4eb5f5d..1249386c 100644 --- a/QXlsx/source/xlsxutility.cpp +++ b/QXlsx/source/xlsxutility.cpp @@ -292,4 +292,9 @@ QString convertSharedFormula(const QString &rootFormula, return result.join(QString()); } +QString xsdBoolean(bool value) +{ + return value ? QStringLiteral("1") : QStringLiteral("0"); +} + QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index e3dd1f46..2843f9b7 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -57,13 +57,6 @@ WorksheetPrivate::WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag) , showWhiteSpace(true) , urlPattern(QStringLiteral("^([fh]tt?ps?://)|(mailto:)|(file://)")) { - previous_row = 0; - - outline_row_level = 0; - outline_col_level = 0; - - default_row_height = 15; - default_row_zeroed = false; } WorksheetPrivate::~WorksheetPrivate() {} @@ -548,7 +541,7 @@ QVariant Worksheet::read(int row, int column) const Cell *Worksheet::cellAt(const CellReference &row_column) const { if (!row_column.isValid()) - return 0; + return nullptr; return cellAt(row_column.row(), row_column.column()); } @@ -562,9 +555,9 @@ Cell *Worksheet::cellAt(int row, int col) const Q_D(const Worksheet); auto it = d->cellTable.constFind(row); if (it == d->cellTable.constEnd()) - return 0; + return nullptr; if (!it->contains(col)) - return 0; + return nullptr; return (*it)[col].get(); } @@ -1324,17 +1317,14 @@ void Worksheet::saveToXmlFile(QIODevice *device) const writer.writeStartElement(QStringLiteral("sheetFormatPr")); writer.writeAttribute(QStringLiteral("defaultRowHeight"), - QString::number(d->default_row_height)); - if (d->default_row_height != 15) - writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1")); - if (d->default_row_zeroed) - writer.writeAttribute(QStringLiteral("zeroHeight"), QStringLiteral("1")); - if (d->outline_row_level) - writer.writeAttribute(QStringLiteral("outlineLevelRow"), - QString::number(d->outline_row_level)); - if (d->outline_col_level) - writer.writeAttribute(QStringLiteral("outlineLevelCol"), - QString::number(d->outline_col_level)); + QString::number(d->sheetFormatProps.defaultRowHeight)); + writer.writeAttribute(QStringLiteral("customHeight"), + xsdBoolean(d->sheetFormatProps.customHeight)); + writer.writeAttribute(QStringLiteral("zeroHeight"), xsdBoolean(d->sheetFormatProps.zeroHeight)); + writer.writeAttribute(QStringLiteral("outlineLevelRow"), + QString::number(d->sheetFormatProps.outlineLevelRow)); + writer.writeAttribute(QStringLiteral("outlineLevelCol"), + QString::number(d->sheetFormatProps.outlineLevelCol)); // for Excel 2010 // writer.writeAttribute("x14ac:dyDescent", "0.25"); writer.writeEndElement(); // sheetFormatPr @@ -2232,7 +2222,7 @@ int WorksheetPrivate::rowPixelsSize(int row) const if (it != row_sizes.constEnd()) height = it.value(); else - height = default_row_height; + height = sheetFormatProps.defaultRowHeight; return static_cast(4.0 / 3.0 * height); }