From edbd6f13f7568717594a46be4f21c4ea792b8bc5 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 | 37 ++++++++++++---------------------- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/QXlsx/header/xlsxutility_p.h b/QXlsx/header/xlsxutility_p.h index 0c8e68f6..c0b476f0 100644 --- a/QXlsx/header/xlsxutility_p.h +++ b/QXlsx/header/xlsxutility_p.h @@ -22,6 +22,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 2241e064..fe82f385 100644 --- a/QXlsx/header/xlsxworksheet_p.h +++ b/QXlsx/header/xlsxworksheet_p.h @@ -192,18 +192,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 dd8680a3..82c2497c 100644 --- a/QXlsx/source/xlsxutility.cpp +++ b/QXlsx/source/xlsxutility.cpp @@ -288,4 +288,9 @@ QString convertSharedFormula(const QString &rootFormula, const CellReference &ro 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 93517045..74df77ac 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -56,13 +56,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() @@ -581,7 +574,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()); } @@ -595,9 +588,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(); } @@ -1353,15 +1346,11 @@ void Worksheet::saveToXmlFile(QIODevice *device) const writer.writeEndElement();//sheetViews 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)); + writer.writeAttribute(QStringLiteral("defaultRowHeight"), 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 @@ -1431,7 +1420,7 @@ void Worksheet::saveToXmlFile(QIODevice *device) const } // dev57 - if ( !d->Prid.isEmpty() ) + if ( d->Prid.isEmpty() ) { writer.writeStartElement(QStringLiteral("pageSetup")); // pageSetup @@ -1562,10 +1551,10 @@ void WorksheetPrivate::saveXmlSheetData(QXmlStreamWriter &writer) const //!Todo: support customHeight from info struct //!Todo: where does this magic number '15' come from? if (rowInfo->customHeight) { - writer.writeAttribute(QStringLiteral("ht"), QString::number(rowInfo->height)); + writer.writeAttribute(QStringLiteral("ht"), QString::number(rowInfo->height)); writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1")); } else { - writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("0")); + writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("false")); } if (rowInfo->hidden) @@ -2302,7 +2291,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); } @@ -2362,7 +2351,7 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) if (attributes.hasAttribute(QLatin1String("customHeight"))) { - info->customHeight = attributes.value(QLatin1String("customHeight")) == QLatin1String("1"); + info->customHeight = attributes.value(QLatin1String("customHeight")) == QLatin1String("1"); //Row height is only specified when customHeight is set if(attributes.hasAttribute(QLatin1String("ht"))) {