From 851e14d32c5600fa55f1c2630b1ef08685008e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=92=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA=D0=B8=D0=BD?= Date: Fri, 9 Nov 2018 18:08:27 +0300 Subject: [PATCH 1/7] Add suport of print area and page setup To set print area of sheet use bool setPrintArea(const CellRange &range, const QString &sheetName=QString()); To set page scaling to percent use bool setPageSetup(double percent, QPageSize::PageSizeId size, QPageLayout::Orientation orientation); To set page scaling to number of pages use bool setPageSetup(int fitToWidth, int fitToHeight, QPageSize::PageSizeId size, QPageLayout::Orientation orientation); --- src/xlsx/xlsxdocument.cpp | 65 +++++++++-- src/xlsx/xlsxdocument.h | 160 ++++++++++++++------------- src/xlsx/xlsxworksheet.cpp | 221 ++++++++++++++++++++++++++++++++----- src/xlsx/xlsxworksheet.h | 11 ++ src/xlsx/xlsxworksheet_p.h | 34 +++++- 5 files changed, 373 insertions(+), 118 deletions(-) diff --git a/src/xlsx/xlsxdocument.cpp b/src/xlsx/xlsxdocument.cpp index 314e789..3d2d9cc 100644 --- a/src/xlsx/xlsxdocument.cpp +++ b/src/xlsx/xlsxdocument.cpp @@ -602,7 +602,7 @@ bool Document::setColumnHidden(int colFirst, int colLast, bool hidden) double Document::columnWidth(int column) { if (Worksheet *sheet = currentWorksheet()) - return sheet->columnWidth(column); + return sheet->columnWidth(column); return 0.0; } @@ -612,7 +612,7 @@ double Document::columnWidth(int column) Format Document::columnFormat(int column) { if (Worksheet *sheet = currentWorksheet()) - return sheet->columnFormat(column); + return sheet->columnFormat(column); return Format(); } @@ -622,7 +622,7 @@ Format Document::columnFormat(int column) bool Document::isColumnHidden(int column) { if (Worksheet *sheet = currentWorksheet()) - return sheet->isColumnHidden(column); + return sheet->isColumnHidden(column); return false; } @@ -646,7 +646,7 @@ bool Document::setRowFormat(int row, const Format &format) bool Document::setRowFormat(int rowFirst, int rowLast, const Format &format) { if (Worksheet *sheet = currentWorksheet()) - return sheet->setRowFormat(rowFirst, rowLast, format); + return sheet->setRowFormat(rowFirst, rowLast, format); return false; } @@ -670,7 +670,7 @@ bool Document::setRowHidden(int row, bool hidden) bool Document::setRowHidden(int rowFirst, int rowLast, bool hidden) { if (Worksheet *sheet = currentWorksheet()) - return sheet->setRowHidden(rowFirst, rowLast, hidden); + return sheet->setRowHidden(rowFirst, rowLast, hidden); return false; } @@ -696,7 +696,7 @@ bool Document::setRowHeight(int row, double height) bool Document::setRowHeight(int rowFirst, int rowLast, double height) { if (Worksheet *sheet = currentWorksheet()) - return sheet->setRowHeight(rowFirst, rowLast, height); + return sheet->setRowHeight(rowFirst, rowLast, height); return false; } @@ -705,8 +705,8 @@ bool Document::setRowHeight(int rowFirst, int rowLast, double height) */ double Document::rowHeight(int row) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->rowHeight(row); + if (Worksheet *sheet = currentWorksheet()) + return sheet->rowHeight(row); return 0.0; } @@ -716,8 +716,8 @@ double Document::rowHeight(int row) Format Document::rowFormat(int row) { if (Worksheet *sheet = currentWorksheet()) - return sheet->rowFormat(row); - return Format(); + return sheet->rowFormat(row); + return Format(); } /*! @@ -726,8 +726,8 @@ Format Document::rowFormat(int row) bool Document::isRowHidden(int row) { if (Worksheet *sheet = currentWorksheet()) - return sheet->isRowHidden(row); - return false; + return sheet->isRowHidden(row); + return false; } /*! @@ -815,6 +815,47 @@ bool Document::defineName(const QString &name, const QString &formula, const QSt return d->workbook->defineName(name, formula, comment, scope); } +/*! + * \brief Create a print area on sheet \a sheetName as cell range \a range + * + * \param sheetName Sheet name to set print ares + * \param range Cell range for print area + */ +bool Document::setPrintArea(const CellRange& range, const QString& sheetName) +{ + Q_D(Document); + + QString sheet = sheetName.isEmpty() + ? currentWorksheet()->sheetName() + : sheetName; + + return d->workbook->defineName(QStringLiteral("_xlnm.Print_Area"), + QString::fromUtf8("%1!%2") + .arg(sheet) + .arg(range.toString(true, true)), + QString(), + sheet); +} + +bool Document::setPageSetup(double percent, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setPageSetup(percent, size, orientation); + return false; +} + +bool Document::setPageSetup(int fitToWidth, + int fitToHeight, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setPageSetup(fitToWidth, fitToHeight, size, orientation); + return false; +} + /*! Return the range that contains cell data. */ diff --git a/src/xlsx/xlsxdocument.h b/src/xlsx/xlsxdocument.h index 7f1113d..7f72888 100644 --- a/src/xlsx/xlsxdocument.h +++ b/src/xlsx/xlsxdocument.h @@ -31,6 +31,8 @@ #include "xlsxworksheet.h" #include #include +#include +#include class QIODevice; class QImage; @@ -47,85 +49,93 @@ class CellReference; class DocumentPrivate; class Q_XLSX_EXPORT Document : public QObject { - Q_OBJECT - Q_DECLARE_PRIVATE(Document) + Q_OBJECT + Q_DECLARE_PRIVATE(Document) public: - explicit Document(QObject *parent = 0); - Document(const QString &xlsxName, QObject *parent=0); - Document(QIODevice *device, QObject *parent=0); - ~Document(); - - bool write(const CellReference &cell, const QVariant &value, const Format &format=Format()); - bool write(int row, int col, const QVariant &value, const Format &format=Format()); - QVariant read(const CellReference &cell) const; - QVariant read(int row, int col) const; - bool insertImage(int row, int col, const QImage &image); - Chart *insertChart(int row, int col, const QSize &size); - bool mergeCells(const CellRange &range, const Format &format=Format()); - bool unmergeCells(const CellRange &range); - - bool setColumnWidth(const CellRange &range, double width); - bool setColumnFormat(const CellRange &range, const Format &format); - bool setColumnHidden(const CellRange &range, bool hidden); - bool setColumnWidth(int column, double width); - bool setColumnFormat(int column, const Format &format); - bool setColumnHidden(int column, bool hidden); - bool setColumnWidth(int colFirst, int colLast, double width); - bool setColumnFormat(int colFirst, int colLast, const Format &format); - bool setColumnHidden(int colFirst, int colLast, bool hidden); - double columnWidth(int column); - Format columnFormat(int column); - bool isColumnHidden(int column); - - bool setRowHeight(int row, double height); - bool setRowFormat(int row, const Format &format); - bool setRowHidden(int row, bool hidden); - bool setRowHeight(int rowFirst, int rowLast, double height); - bool setRowFormat(int rowFirst, int rowLast, const Format &format); - bool setRowHidden(int rowFirst, int rowLast, bool hidden); - - double rowHeight(int row); - Format rowFormat(int row); - bool isRowHidden(int row); - - bool groupRows(int rowFirst, int rowLast, bool collapsed = true); - bool groupColumns(int colFirst, int colLast, bool collapsed = true); - bool addDataValidation(const DataValidation &validation); - bool addConditionalFormatting(const ConditionalFormatting &cf); - - Cell *cellAt(const CellReference &cell) const; - Cell *cellAt(int row, int col) const; - - bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString()); - - CellRange dimension() const; - - QString documentProperty(const QString &name) const; - void setDocumentProperty(const QString &name, const QString &property); - QStringList documentPropertyNames() const; - - QStringList sheetNames() const; - bool addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); - bool insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); - bool selectSheet(const QString &name); - bool renameSheet(const QString &oldName, const QString &newName); - bool copySheet(const QString &srcName, const QString &distName = QString()); - bool moveSheet(const QString &srcName, int distIndex); - bool deleteSheet(const QString &name); - - Workbook *workbook() const; - AbstractSheet *sheet(const QString &sheetName) const; - AbstractSheet *currentSheet() const; - Worksheet *currentWorksheet() const; - - bool save() const; - bool saveAs(const QString &xlsXname) const; - bool saveAs(QIODevice *device) const; + explicit Document(QObject *parent = 0); + Document(const QString &xlsxName, QObject *parent=0); + Document(QIODevice *device, QObject *parent=0); + ~Document(); + + bool write(const CellReference &cell, const QVariant &value, const Format &format=Format()); + bool write(int row, int col, const QVariant &value, const Format &format=Format()); + QVariant read(const CellReference &cell) const; + QVariant read(int row, int col) const; + bool insertImage(int row, int col, const QImage &image); + Chart *insertChart(int row, int col, const QSize &size); + bool mergeCells(const CellRange &range, const Format &format=Format()); + bool unmergeCells(const CellRange &range); + + bool setColumnWidth(const CellRange &range, double width); + bool setColumnFormat(const CellRange &range, const Format &format); + bool setColumnHidden(const CellRange &range, bool hidden); + bool setColumnWidth(int column, double width); + bool setColumnFormat(int column, const Format &format); + bool setColumnHidden(int column, bool hidden); + bool setColumnWidth(int colFirst, int colLast, double width); + bool setColumnFormat(int colFirst, int colLast, const Format &format); + bool setColumnHidden(int colFirst, int colLast, bool hidden); + double columnWidth(int column); + Format columnFormat(int column); + bool isColumnHidden(int column); + + bool setRowHeight(int row, double height); + bool setRowFormat(int row, const Format &format); + bool setRowHidden(int row, bool hidden); + bool setRowHeight(int rowFirst, int rowLast, double height); + bool setRowFormat(int rowFirst, int rowLast, const Format &format); + bool setRowHidden(int rowFirst, int rowLast, bool hidden); + + double rowHeight(int row); + Format rowFormat(int row); + bool isRowHidden(int row); + + bool groupRows(int rowFirst, int rowLast, bool collapsed = true); + bool groupColumns(int colFirst, int colLast, bool collapsed = true); + bool addDataValidation(const DataValidation &validation); + bool addConditionalFormatting(const ConditionalFormatting &cf); + + Cell *cellAt(const CellReference &cell) const; + Cell *cellAt(int row, int col) const; + + bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString()); + bool setPrintArea(const CellRange &range, const QString &sheetName=QString()); + bool setPageSetup(double percent, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation); + bool setPageSetup(int fitToWidth, + int fitToHeight, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation); + + CellRange dimension() const; + + QString documentProperty(const QString &name) const; + void setDocumentProperty(const QString &name, const QString &property); + QStringList documentPropertyNames() const; + + QStringList sheetNames() const; + bool addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + bool insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + bool selectSheet(const QString &name); + bool renameSheet(const QString &oldName, const QString &newName); + bool copySheet(const QString &srcName, const QString &distName = QString()); + bool moveSheet(const QString &srcName, int distIndex); + bool deleteSheet(const QString &name); + + Workbook *workbook() const; + AbstractSheet *sheet(const QString &sheetName) const; + AbstractSheet *currentSheet() const; + Worksheet *currentWorksheet() const; + + bool save() const; + bool saveAs(const QString &xlsXname) const; + bool saveAs(QIODevice *device) const; private: - Q_DISABLE_COPY(Document) - DocumentPrivate * const d_ptr; + Q_DISABLE_COPY(Document) + DocumentPrivate * const d_ptr; }; QT_END_NAMESPACE_XLSX diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 8311dd3..154b146 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -61,9 +61,9 @@ QT_BEGIN_NAMESPACE_XLSX WorksheetPrivate::WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag) : AbstractSheetPrivate(p, flag) - , windowProtection(false), showFormulas(false), showGridLines(true), showRowColHeaders(true) - , showZeros(true), rightToLeft(false), tabSelected(false), showRuler(false) - , showOutlineSymbols(true), showWhiteSpace(true), urlPattern(QStringLiteral("^([fh]tt?ps?://)|(mailto:)|(file://)")) + , windowProtection(false), showFormulas(false), showGridLines(true), showRowColHeaders(true) + , showZeros(true), rightToLeft(false), tabSelected(false), showRuler(false) + , showOutlineSymbols(true), showWhiteSpace(true), urlPattern(QStringLiteral("^([fh]tt?ps?://)|(mailto:)|(file://)")) { previous_row = 0; @@ -218,11 +218,11 @@ Worksheet *Worksheet::copy(const QString &distName, int distId) const } sheet_d->merges = d->merges; -// sheet_d->rowsInfo = d->rowsInfo; -// sheet_d->colsInfo = d->colsInfo; -// sheet_d->colsInfoHelper = d->colsInfoHelper; -// sheet_d->dataValidationsList = d->dataValidationsList; -// sheet_d->conditionalFormattingList = d->conditionalFormattingList; + // sheet_d->rowsInfo = d->rowsInfo; + // sheet_d->colsInfo = d->colsInfo; + // sheet_d->colsInfoHelper = d->colsInfoHelper; + // sheet_d->dataValidationsList = d->dataValidationsList; + // sheet_d->conditionalFormattingList = d->conditionalFormattingList; return sheet; } @@ -604,14 +604,14 @@ bool Worksheet::writeString(const CellReference &row_column, const RichString &v bool Worksheet::writeString(int row, int column, const RichString &value, const Format &format) { Q_D(Worksheet); -// QString content = value.toPlainString(); + // QString content = value.toPlainString(); if (d->checkDimensions(row, column)) return false; -// if (content.size() > d->xls_strmax) { -// content = content.left(d->xls_strmax); -// error = -2; -// } + // if (content.size() > d->xls_strmax) { + // content = content.left(d->xls_strmax); + // error = -2; + // } d->sharedStrings()->addSharedString(value); Format fmt = format.isValid() ? format : d->cellFormat(row, column); @@ -1154,6 +1154,15 @@ void Worksheet::saveToXmlFile(QIODevice *device) const // writer.writeAttribute("xmlns:x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); // writer.writeAttribute("mc:Ignorable", "x14ac"); + if (d->pageSetup.isFitToPage()) + { + writer.writeStartElement(QStringLiteral("sheetPr")); + writer.writeStartElement(QStringLiteral("pageSetUpPr")); + writer.writeAttribute(QStringLiteral("fitToPage"), QString::number(d->pageSetup.fitToHeight)); + writer.writeEndElement();//pageSetUpPr + writer.writeEndElement();//sheetPr + } + writer.writeStartElement(QStringLiteral("dimension")); writer.writeAttribute(QStringLiteral("ref"), d->generateDimensionString()); writer.writeEndElement();//dimension @@ -1234,6 +1243,17 @@ void Worksheet::saveToXmlFile(QIODevice *device) const cf.saveToXml(writer); d->saveXmlDataValidations(writer); d->saveXmlHyperlinks(writer); + + if (d->pageSetup.isValid()) + { + writer.writeStartElement(QStringLiteral("pageSetup")); + writer.writeAttribute(QStringLiteral("paperSize"), QString::number(d->pageSetup.xlsxPageSize())); + if (d->pageSetup.isScale()) writer.writeAttribute(QStringLiteral("scale"), QString::number(d->pageSetup.scale)); + else if (d->pageSetup.isFitToPage()) writer.writeAttribute(QStringLiteral("fitToHeight"), QString::number(d->pageSetup.fitToHeight)); + writer.writeAttribute(QStringLiteral("orientation"), d->pageSetup.orientationString()); + writer.writeEndElement();//pageSetup + } + d->saveXmlDrawings(writer); writer.writeEndElement();//worksheet @@ -1572,7 +1592,7 @@ bool Worksheet::setColumnWidth(int colFirst, int colLast, double width) QList > columnInfoList = d->getColumnInfoList(colFirst, colLast); foreach(QSharedPointer columnInfo, columnInfoList) - columnInfo->width = width; + columnInfo->width = width; return (columnInfoList.count() > 0); } @@ -1588,11 +1608,11 @@ bool Worksheet::setColumnFormat(int colFirst, int colLast, const Format &format) QList > columnInfoList = d->getColumnInfoList(colFirst, colLast); foreach(QSharedPointer columnInfo, columnInfoList) - columnInfo->format = format; + columnInfo->format = format; if(columnInfoList.count() > 0) { - d->workbook->styles()->addXfFormat(format); - return true; + d->workbook->styles()->addXfFormat(format); + return true; } return false; @@ -1608,7 +1628,7 @@ bool Worksheet::setColumnHidden(int colFirst, int colLast, bool hidden) QList > columnInfoList = d->getColumnInfoList(colFirst, colLast); foreach(QSharedPointer columnInfo, columnInfoList) - columnInfo->hidden = hidden; + columnInfo->hidden = hidden; return (columnInfoList.count() > 0); } @@ -1622,7 +1642,7 @@ double Worksheet::columnWidth(int column) QList > columnInfoList = d->getColumnInfoList(column, column); if (columnInfoList.count() == 1) - return columnInfoList.at(0)->width ; + return columnInfoList.at(0)->width ; return d->sheetFormatProps.defaultColWidth; } @@ -1636,7 +1656,7 @@ Format Worksheet::columnFormat(int column) QList > columnInfoList = d->getColumnInfoList(column, column); if (columnInfoList.count() == 1) - return columnInfoList.at(0)->format; + return columnInfoList.at(0)->format; return Format(); } @@ -1650,7 +1670,7 @@ bool Worksheet::isColumnHidden(int column) QList > columnInfoList = d->getColumnInfoList(column, column); if (columnInfoList.count() == 1) - return columnInfoList.at(0)->hidden; + return columnInfoList.at(0)->hidden; return false; } @@ -1860,6 +1880,20 @@ CellRange Worksheet::dimension() const return d->dimension; } +bool Worksheet::setPageSetup(double percent, QPageSize::PageSizeId size, QPageLayout::Orientation orientation) +{ + Q_D(Worksheet); + d->pageSetup = WorksheetPrivate::PageSetup(percent, size, orientation); + return true; +} + +bool Worksheet::setPageSetup(int fitToWidth, int fitToHeight, QPageSize::PageSizeId size, QPageLayout::Orientation orientation) +{ + Q_D(Worksheet); + d->pageSetup = WorksheetPrivate::PageSetup(fitToWidth, fitToHeight, size, orientation); + return true; +} + /* Convert the height of a cell from user's units to pixels. If the height hasn't been set by the user we use the default value. If @@ -1910,10 +1944,10 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) QXmlStreamAttributes attributes = reader.attributes(); if (attributes.hasAttribute(QLatin1String("customFormat")) - || attributes.hasAttribute(QLatin1String("customHeight")) - || attributes.hasAttribute(QLatin1String("hidden")) - || attributes.hasAttribute(QLatin1String("outlineLevel")) - || attributes.hasAttribute(QLatin1String("collapsed"))) { + || attributes.hasAttribute(QLatin1String("customHeight")) + || attributes.hasAttribute(QLatin1String("hidden")) + || attributes.hasAttribute(QLatin1String("outlineLevel")) + || attributes.hasAttribute(QLatin1String("collapsed"))) { QSharedPointer info(new XlsxRowInfo); if (attributes.hasAttribute(QLatin1String("customFormat")) && attributes.hasAttribute(QLatin1String("s"))) { @@ -2098,10 +2132,10 @@ void WorksheetPrivate::loadXmlDataValidations(QXmlStreamReader &reader) int count = attributes.value(QLatin1String("count")).toString().toInt(); while (!reader.atEnd() && !(reader.name() == QLatin1String("dataValidations") - && reader.tokenType() == QXmlStreamReader::EndElement)) { + && reader.tokenType() == QXmlStreamReader::EndElement)) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement - && reader.name() == QLatin1String("dataValidation")) { + && reader.name() == QLatin1String("dataValidation")) { dataValidationsList.append(DataValidation::loadFromXml(reader)); } } @@ -2115,7 +2149,7 @@ void WorksheetPrivate::loadXmlSheetViews(QXmlStreamReader &reader) Q_ASSERT(reader.name() == QLatin1String("sheetViews")); while (!reader.atEnd() && !(reader.name() == QLatin1String("sheetViews") - && reader.tokenType() == QXmlStreamReader::EndElement)) { + && reader.tokenType() == QXmlStreamReader::EndElement)) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement && reader.name() == QLatin1String("sheetView")) { QXmlStreamAttributes attrs = reader.attributes(); @@ -2165,7 +2199,7 @@ void WorksheetPrivate::loadXmlSheetFormatProps(QXmlStreamReader &reader) } if(formatProps.defaultColWidth == 0.0) { //not set - formatProps.defaultColWidth = WorksheetPrivate::calculateColWidth(formatProps.baseColWidth); + formatProps.defaultColWidth = WorksheetPrivate::calculateColWidth(formatProps.baseColWidth); } } @@ -2181,7 +2215,7 @@ void WorksheetPrivate::loadXmlHyperlinks(QXmlStreamReader &reader) Q_ASSERT(reader.name() == QLatin1String("hyperlinks")); while (!reader.atEnd() && !(reader.name() == QLatin1String("hyperlinks") - && reader.tokenType() == QXmlStreamReader::EndElement)) { + && reader.tokenType() == QXmlStreamReader::EndElement)) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement && reader.name() == QLatin1String("hyperlink")) { QXmlStreamAttributes attrs = reader.attributes(); @@ -2206,6 +2240,32 @@ void WorksheetPrivate::loadXmlHyperlinks(QXmlStreamReader &reader) } } +void WorksheetPrivate::loadXmlSheetPr(QXmlStreamReader& reader) +{ + Q_ASSERT(reader.name() == QLatin1String("sheetPr")); + + while (!reader.atEnd() && !(reader.name() == QLatin1String("sheetPr") + && reader.tokenType() == QXmlStreamReader::EndElement)) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement + && reader.name() == QLatin1String("pageSetUpPr")) { + QXmlStreamAttributes attributes = reader.attributes(); + pageSetup.fitToWidth = attributes.value(QLatin1String("fitToPage")).toInt(); + } + } +} + +void WorksheetPrivate::loadXmlPageSetup(QXmlStreamReader& reader) +{ + Q_ASSERT(reader.name() == QLatin1String("pageSetup")); + + QXmlStreamAttributes attributes = reader.attributes(); + pageSetup.scale = attributes.value(QLatin1String("scale")).toDouble(); + pageSetup.fitToHeight = attributes.value(QLatin1String("fitToHeight")).toInt(); + pageSetup.orientation = PageSetup::fromOrientationString(attributes.value(QLatin1String("orientation")).toString()); + pageSetup.pageSize = PageSetup::fromXlsxPageSize(attributes.value(QLatin1String("paperSize")).toInt()); +} + QList > WorksheetPrivate::getColumnInfoList(int colFirst, int colLast) { QList > columnsInfoList; @@ -2264,6 +2324,8 @@ bool Worksheet::loadFromXmlFile(QIODevice *device) QXmlStreamAttributes attributes = reader.attributes(); QString range = attributes.value(QLatin1String("ref")).toString(); d->dimension = CellRange(range); + } else if (reader.name() == QLatin1String("sheetPr")) { + d->loadXmlSheetPr(reader); } else if (reader.name() == QLatin1String("sheetViews")) { d->loadXmlSheetViews(reader); } else if (reader.name() == QLatin1String("sheetFormatPr")) { @@ -2282,6 +2344,8 @@ bool Worksheet::loadFromXmlFile(QIODevice *device) d->conditionalFormattingList.append(cf); } else if (reader.name() == QLatin1String("hyperlinks")) { d->loadXmlHyperlinks(reader); + } else if (reader.name() == QLatin1String("pageSetup")) { + d->loadXmlPageSetup(reader); } else if (reader.name() == QLatin1String("drawing")) { QString rId = reader.attributes().value(QStringLiteral("r:id")).toString(); QString name = d->relationships->getRelationshipById(rId).target; @@ -2341,4 +2405,101 @@ SharedStrings *WorksheetPrivate::sharedStrings() const return workbook->sharedStrings(); } +WorksheetPrivate::PageSetup::PageSetup(): + scale(0), + fitToWidth(0), + fitToHeight(0), + pageSize(QPageSize::A4), + orientation(QPageLayout::Portrait) +{ +} + +WorksheetPrivate::PageSetup::PageSetup(double _scale, + QPageSize::PageSizeId _pageSize, + QPageLayout::Orientation _orientation) : + scale(_scale), + fitToWidth(0), + fitToHeight(0), + pageSize(_pageSize), + orientation(_orientation) +{ +} + +WorksheetPrivate::PageSetup::PageSetup(int _fitToWidth, + int _fitToHeight, + QPageSize::PageSizeId _pageSize, + QPageLayout::Orientation _orientation) : + scale(0), + fitToWidth(_fitToWidth), + fitToHeight(_fitToHeight), + pageSize(_pageSize), + orientation(_orientation) +{ +} + +bool WorksheetPrivate::PageSetup::isScale() const +{ + return scale > 0; +} + +bool WorksheetPrivate::PageSetup::isFitToPage() const +{ + return (fitToWidth > 0) && (fitToHeight > 0); +} + +bool WorksheetPrivate::PageSetup::isValid() const +{ + return isFitToPage() || isScale(); +} + +int WorksheetPrivate::PageSetup::xlsxPageSize() const +{ + switch (pageSize) + { + case QPageSize::A2: return 257; + case QPageSize::A3: return 8; + case QPageSize::A4: return 9; + case QPageSize::A5: return 11; + case QPageSize::A6: return 260; + case QPageSize::B3: return 259; + case QPageSize::B4: return 12; + case QPageSize::B5: return 13; + case QPageSize::Letter: return 1; + case QPageSize::A3Extra: return 258; + default: break; + } + return 0; +} + +QPageSize::PageSizeId WorksheetPrivate::PageSetup::fromXlsxPageSize(int xlsxPageSize) +{ + switch (xlsxPageSize) + { + case 1: return QPageSize::Letter; + case 8: return QPageSize::A3; + case 11: return QPageSize::A5; + case 12: return QPageSize::B4; + case 13: return QPageSize::B5; + case 257: return QPageSize::A2; + case 258: return QPageSize::A3Extra; + case 259: return QPageSize::B3; + case 260: return QPageSize::A6; + default: break; + } + return QPageSize::A4; +} + +QString WorksheetPrivate::PageSetup::orientationString() const +{ + return (orientation == QPageLayout::Landscape) + ? QStringLiteral("landscape") + : QStringLiteral("portrait"); +} + +QPageLayout::Orientation WorksheetPrivate::PageSetup::fromOrientationString(const QString& str) +{ + if (!str.compare(QStringLiteral("landscape"), Qt::CaseInsensitive)) return QPageLayout::Landscape; + return QPageLayout::Portrait; +} + QT_END_NAMESPACE_XLSX diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index 6883370..2641e97 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -34,6 +34,9 @@ #include #include #include +#include +#include + class QIODevice; class QDateTime; class QUrl; @@ -119,6 +122,14 @@ class Q_XLSX_EXPORT Worksheet : public AbstractSheet bool groupColumns(const CellRange &range, bool collapsed = true); CellRange dimension() const; + bool setPageSetup(double percent, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation); + bool setPageSetup(int fitToWidth, + int fitToHeight, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation); + bool isWindowProtected() const; void setWindowProtected(bool protect); bool isFormulasVisible() const; diff --git a/src/xlsx/xlsxworksheet_p.h b/src/xlsx/xlsxworksheet_p.h index b3f5849..c18978a 100644 --- a/src/xlsx/xlsxworksheet_p.h +++ b/src/xlsx/xlsxworksheet_p.h @@ -46,6 +46,8 @@ #include #include #include +#include +#include class QXmlStreamWriter; class QXmlStreamReader; @@ -142,7 +144,7 @@ struct XlsxColumnInfo int firstColumn; int lastColumn; bool customWidth; - double width; + double width; Format format; bool hidden; int outlineLevel; @@ -153,6 +155,32 @@ class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public AbstractSheetPrivate { Q_DECLARE_PUBLIC(Worksheet) public: + struct PageSetup + { + double scale; + int fitToWidth; + int fitToHeight; + QPageSize::PageSizeId pageSize; + QPageLayout::Orientation orientation; + + PageSetup(); + PageSetup(double _scale, + QPageSize::PageSizeId _pageSize, + QPageLayout::Orientation _orientation); + PageSetup(int _fitToWidth, + int _fitToHeight, + QPageSize::PageSizeId _pageSize, + QPageLayout::Orientation _orientation); + bool isScale() const; + bool isFitToPage() const; + bool isValid() const; + + int xlsxPageSize() const; + static QPageSize::PageSizeId fromXlsxPageSize(int xlsxPageSize); + QString orientationString() const; + static QPageLayout::Orientation fromOrientationString(const QString& str); + }; + WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag); ~WorksheetPrivate(); int checkDimensions(int row, int col, bool ignore_row=false, bool ignore_col=false); @@ -178,6 +206,8 @@ class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public AbstractSheetPrivate void loadXmlSheetFormatProps(QXmlStreamReader &reader); void loadXmlSheetViews(QXmlStreamReader &reader); void loadXmlHyperlinks(QXmlStreamReader &reader); + void loadXmlSheetPr(QXmlStreamReader &reader); + void loadXmlPageSetup(QXmlStreamReader &reader); QList > getRowInfoList(int rowFirst, int rowLast); QList > getColumnInfoList(int colFirst, int colLast); @@ -224,6 +254,8 @@ class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public AbstractSheetPrivate bool showOutlineSymbols; bool showWhiteSpace; + PageSetup pageSetup; + QRegularExpression urlPattern; private: static double calculateColWidth(int characters); From 1c3ff283701a73ac2feb653c37d41bcb061e080f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=92=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA=D0=B8=D0=BD?= Date: Fri, 9 Nov 2018 18:18:01 +0300 Subject: [PATCH 2/7] Formatting --- src/xlsx/xlsxdocument.h | 166 ++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/xlsx/xlsxdocument.h b/src/xlsx/xlsxdocument.h index 7f72888..9befebd 100644 --- a/src/xlsx/xlsxdocument.h +++ b/src/xlsx/xlsxdocument.h @@ -49,93 +49,93 @@ class CellReference; class DocumentPrivate; class Q_XLSX_EXPORT Document : public QObject { - Q_OBJECT - Q_DECLARE_PRIVATE(Document) + Q_OBJECT + Q_DECLARE_PRIVATE(Document) public: - explicit Document(QObject *parent = 0); - Document(const QString &xlsxName, QObject *parent=0); - Document(QIODevice *device, QObject *parent=0); - ~Document(); - - bool write(const CellReference &cell, const QVariant &value, const Format &format=Format()); - bool write(int row, int col, const QVariant &value, const Format &format=Format()); - QVariant read(const CellReference &cell) const; - QVariant read(int row, int col) const; - bool insertImage(int row, int col, const QImage &image); - Chart *insertChart(int row, int col, const QSize &size); - bool mergeCells(const CellRange &range, const Format &format=Format()); - bool unmergeCells(const CellRange &range); - - bool setColumnWidth(const CellRange &range, double width); - bool setColumnFormat(const CellRange &range, const Format &format); - bool setColumnHidden(const CellRange &range, bool hidden); - bool setColumnWidth(int column, double width); - bool setColumnFormat(int column, const Format &format); - bool setColumnHidden(int column, bool hidden); - bool setColumnWidth(int colFirst, int colLast, double width); - bool setColumnFormat(int colFirst, int colLast, const Format &format); - bool setColumnHidden(int colFirst, int colLast, bool hidden); - double columnWidth(int column); - Format columnFormat(int column); - bool isColumnHidden(int column); - - bool setRowHeight(int row, double height); - bool setRowFormat(int row, const Format &format); - bool setRowHidden(int row, bool hidden); - bool setRowHeight(int rowFirst, int rowLast, double height); - bool setRowFormat(int rowFirst, int rowLast, const Format &format); - bool setRowHidden(int rowFirst, int rowLast, bool hidden); - - double rowHeight(int row); - Format rowFormat(int row); - bool isRowHidden(int row); - - bool groupRows(int rowFirst, int rowLast, bool collapsed = true); - bool groupColumns(int colFirst, int colLast, bool collapsed = true); - bool addDataValidation(const DataValidation &validation); - bool addConditionalFormatting(const ConditionalFormatting &cf); - - Cell *cellAt(const CellReference &cell) const; - Cell *cellAt(int row, int col) const; - - bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString()); - bool setPrintArea(const CellRange &range, const QString &sheetName=QString()); - bool setPageSetup(double percent, - QPageSize::PageSizeId size, - QPageLayout::Orientation orientation); - bool setPageSetup(int fitToWidth, - int fitToHeight, - QPageSize::PageSizeId size, - QPageLayout::Orientation orientation); - - CellRange dimension() const; - - QString documentProperty(const QString &name) const; - void setDocumentProperty(const QString &name, const QString &property); - QStringList documentPropertyNames() const; - - QStringList sheetNames() const; - bool addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); - bool insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); - bool selectSheet(const QString &name); - bool renameSheet(const QString &oldName, const QString &newName); - bool copySheet(const QString &srcName, const QString &distName = QString()); - bool moveSheet(const QString &srcName, int distIndex); - bool deleteSheet(const QString &name); - - Workbook *workbook() const; - AbstractSheet *sheet(const QString &sheetName) const; - AbstractSheet *currentSheet() const; - Worksheet *currentWorksheet() const; - - bool save() const; - bool saveAs(const QString &xlsXname) const; - bool saveAs(QIODevice *device) const; + explicit Document(QObject *parent = 0); + Document(const QString &xlsxName, QObject *parent=0); + Document(QIODevice *device, QObject *parent=0); + ~Document(); + + bool write(const CellReference &cell, const QVariant &value, const Format &format=Format()); + bool write(int row, int col, const QVariant &value, const Format &format=Format()); + QVariant read(const CellReference &cell) const; + QVariant read(int row, int col) const; + bool insertImage(int row, int col, const QImage &image); + Chart *insertChart(int row, int col, const QSize &size); + bool mergeCells(const CellRange &range, const Format &format=Format()); + bool unmergeCells(const CellRange &range); + + bool setColumnWidth(const CellRange &range, double width); + bool setColumnFormat(const CellRange &range, const Format &format); + bool setColumnHidden(const CellRange &range, bool hidden); + bool setColumnWidth(int column, double width); + bool setColumnFormat(int column, const Format &format); + bool setColumnHidden(int column, bool hidden); + bool setColumnWidth(int colFirst, int colLast, double width); + bool setColumnFormat(int colFirst, int colLast, const Format &format); + bool setColumnHidden(int colFirst, int colLast, bool hidden); + double columnWidth(int column); + Format columnFormat(int column); + bool isColumnHidden(int column); + + bool setRowHeight(int row, double height); + bool setRowFormat(int row, const Format &format); + bool setRowHidden(int row, bool hidden); + bool setRowHeight(int rowFirst, int rowLast, double height); + bool setRowFormat(int rowFirst, int rowLast, const Format &format); + bool setRowHidden(int rowFirst, int rowLast, bool hidden); + + double rowHeight(int row); + Format rowFormat(int row); + bool isRowHidden(int row); + + bool groupRows(int rowFirst, int rowLast, bool collapsed = true); + bool groupColumns(int colFirst, int colLast, bool collapsed = true); + bool addDataValidation(const DataValidation &validation); + bool addConditionalFormatting(const ConditionalFormatting &cf); + + Cell *cellAt(const CellReference &cell) const; + Cell *cellAt(int row, int col) const; + + bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString()); + bool setPrintArea(const CellRange &range, const QString &sheetName=QString()); + bool setPageSetup(double percent, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation); + bool setPageSetup(int fitToWidth, + int fitToHeight, + QPageSize::PageSizeId size, + QPageLayout::Orientation orientation); + + CellRange dimension() const; + + QString documentProperty(const QString &name) const; + void setDocumentProperty(const QString &name, const QString &property); + QStringList documentPropertyNames() const; + + QStringList sheetNames() const; + bool addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + bool insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + bool selectSheet(const QString &name); + bool renameSheet(const QString &oldName, const QString &newName); + bool copySheet(const QString &srcName, const QString &distName = QString()); + bool moveSheet(const QString &srcName, int distIndex); + bool deleteSheet(const QString &name); + + Workbook *workbook() const; + AbstractSheet *sheet(const QString &sheetName) const; + AbstractSheet *currentSheet() const; + Worksheet *currentWorksheet() const; + + bool save() const; + bool saveAs(const QString &xlsXname) const; + bool saveAs(QIODevice *device) const; private: - Q_DISABLE_COPY(Document) - DocumentPrivate * const d_ptr; + Q_DISABLE_COPY(Document) + DocumentPrivate * const d_ptr; }; QT_END_NAMESPACE_XLSX From cb3293456fdd089a69a1d71655cfbf51f8cf9199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=92=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA=D0=B8=D0=BD?= Date: Fri, 9 Nov 2018 18:46:50 +0300 Subject: [PATCH 3/7] Fixing errors --- src/xlsx/xlsxworksheet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 154b146..95f154f 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -1158,7 +1158,7 @@ void Worksheet::saveToXmlFile(QIODevice *device) const { writer.writeStartElement(QStringLiteral("sheetPr")); writer.writeStartElement(QStringLiteral("pageSetUpPr")); - writer.writeAttribute(QStringLiteral("fitToPage"), QString::number(d->pageSetup.fitToHeight)); + writer.writeAttribute(QStringLiteral("fitToPage"), QString::number(d->pageSetup.fitToWidth)); writer.writeEndElement();//pageSetUpPr writer.writeEndElement();//sheetPr } From 40de369bb35553f44b5928f1be3f3dced53622eb Mon Sep 17 00:00:00 2001 From: tavplubix Date: Mon, 19 Nov 2018 10:03:17 +0300 Subject: [PATCH 4/7] Page breaks and multiline text - support of manual row breaks and column breaks - better multiline text format --- src/xlsx/xlsxsharedstrings.cpp | 14 ++++++++-- src/xlsx/xlsxworksheet.cpp | 47 ++++++++++++++++++++++++++++++++++ src/xlsx/xlsxworksheet.h | 3 +++ src/xlsx/xlsxworksheet_p.h | 2 ++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/xlsx/xlsxsharedstrings.cpp b/src/xlsx/xlsxsharedstrings.cpp index 129d0a1..8029767 100755 --- a/src/xlsx/xlsxsharedstrings.cpp +++ b/src/xlsx/xlsxsharedstrings.cpp @@ -228,13 +228,23 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const writer.writeStartElement(QStringLiteral("si")); if (string.isRichString()) { //Rich text string + Format lastNotEmptyFragmentFormat; for (int i=0; ishowWhiteSpace = visible; } +/*! + * Add manual page break above the specified row \a row (1-indexed) + */ +void Worksheet::addRowBreak(int row) +{ + Q_D(Worksheet); + d->rowBreaks.insert(row); +} + +/*! + * Add manual page break left of the specified column \a col (1-indexed) + */ +void Worksheet::addColBreak(int col) +{ + Q_D(Worksheet); + d->colBreaks.insert(col); +} /*! * Write \a value to cell (\a row, \a column) with the \a format. @@ -1254,6 +1271,36 @@ void Worksheet::saveToXmlFile(QIODevice *device) const writer.writeEndElement();//pageSetup } + if (!d->rowBreaks.isEmpty()) + { + writer.writeStartElement(QStringLiteral("rowBreaks")); + writer.writeAttribute(QStringLiteral("count"), QString::number(d->rowBreaks.count())); + writer.writeAttribute(QStringLiteral("manualBreakCount"), QString::number(d->rowBreaks.count())); + foreach (const int r, d->rowBreaks) + { + writer.writeEmptyElement(QStringLiteral("brk")); + writer.writeAttribute(QStringLiteral("id"), QString::number(r - 1)); + writer.writeAttribute(QStringLiteral("max"), QString::number(16383)); + writer.writeAttribute(QStringLiteral("man"), QString::number(1)); + } + writer.writeEndElement();//rowBreaks + } + + if (!d->colBreaks.isEmpty()) + { + writer.writeStartElement(QStringLiteral("colBreaks")); + writer.writeAttribute(QStringLiteral("count"), QString::number(d->rowBreaks.count())); + writer.writeAttribute(QStringLiteral("manualBreakCount"), QString::number(d->rowBreaks.count())); + foreach (const int c, d->colBreaks) + { + writer.writeEmptyElement(QStringLiteral("brk")); + writer.writeAttribute(QStringLiteral("id"), QString::number(c - 1)); + writer.writeAttribute(QStringLiteral("max"), QString::number(1048575)); + writer.writeAttribute(QStringLiteral("man"), QString::number(1)); + } + writer.writeEndElement();//colBreaks + } + d->saveXmlDrawings(writer); writer.writeEndElement();//worksheet diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index 2641e97..6cb4377 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -151,6 +151,9 @@ class Q_XLSX_EXPORT Worksheet : public AbstractSheet bool isWhiteSpaceVisible() const; void setWhiteSpaceVisible(bool visible); + void addRowBreak(int row); + void addColBreak(int col); + ~Worksheet(); diff --git a/src/xlsx/xlsxworksheet_p.h b/src/xlsx/xlsxworksheet_p.h index c18978a..a7caa59 100644 --- a/src/xlsx/xlsxworksheet_p.h +++ b/src/xlsx/xlsxworksheet_p.h @@ -234,6 +234,8 @@ class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public AbstractSheetPrivate mutable QMap row_spans; QMap row_sizes; QMap col_sizes; + QSet rowBreaks; + QSet colBreaks; int outline_row_level; int outline_col_level; From 52d822407c9cbed4ef060be8276deab8346dd329 Mon Sep 17 00:00:00 2001 From: tavplubix Date: Tue, 20 Nov 2018 11:51:02 +0300 Subject: [PATCH 5/7] Fix PageSetup - 0 is valid value for fitToWidth and fitToHeight, which means "Auto" --- src/xlsx/xlsxworksheet.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 4744746..89eb513 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -56,6 +56,7 @@ #include #include +#include QT_BEGIN_NAMESPACE_XLSX @@ -1276,7 +1277,9 @@ void Worksheet::saveToXmlFile(QIODevice *device) const writer.writeStartElement(QStringLiteral("rowBreaks")); writer.writeAttribute(QStringLiteral("count"), QString::number(d->rowBreaks.count())); writer.writeAttribute(QStringLiteral("manualBreakCount"), QString::number(d->rowBreaks.count())); - foreach (const int r, d->rowBreaks) + QList sortedBreaks = d->rowBreaks.toList(); + std::sort(sortedBreaks.begin(), sortedBreaks.end()); + foreach (const int r, sortedBreaks) { writer.writeEmptyElement(QStringLiteral("brk")); writer.writeAttribute(QStringLiteral("id"), QString::number(r - 1)); @@ -1291,7 +1294,9 @@ void Worksheet::saveToXmlFile(QIODevice *device) const writer.writeStartElement(QStringLiteral("colBreaks")); writer.writeAttribute(QStringLiteral("count"), QString::number(d->rowBreaks.count())); writer.writeAttribute(QStringLiteral("manualBreakCount"), QString::number(d->rowBreaks.count())); - foreach (const int c, d->colBreaks) + QList sortedBreaks = d->colBreaks.toList(); + std::sort(sortedBreaks.begin(), sortedBreaks.end()); + foreach (const int c, sortedBreaks) { writer.writeEmptyElement(QStringLiteral("brk")); writer.writeAttribute(QStringLiteral("id"), QString::number(c - 1)); @@ -2454,8 +2459,8 @@ SharedStrings *WorksheetPrivate::sharedStrings() const WorksheetPrivate::PageSetup::PageSetup(): scale(0), - fitToWidth(0), - fitToHeight(0), + fitToWidth(-1), + fitToHeight(-1), pageSize(QPageSize::A4), orientation(QPageLayout::Portrait) { @@ -2465,8 +2470,8 @@ WorksheetPrivate::PageSetup::PageSetup(double _scale, QPageSize::PageSizeId _pageSize, QPageLayout::Orientation _orientation) : scale(_scale), - fitToWidth(0), - fitToHeight(0), + fitToWidth(-1), + fitToHeight(-1), pageSize(_pageSize), orientation(_orientation) { @@ -2491,7 +2496,7 @@ bool WorksheetPrivate::PageSetup::isScale() const bool WorksheetPrivate::PageSetup::isFitToPage() const { - return (fitToWidth > 0) && (fitToHeight > 0); + return (fitToWidth >= 0) && (fitToHeight >= 0); } bool WorksheetPrivate::PageSetup::isValid() const From c470e9155b6c13430f80c955574ea3eb5edc5314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=92=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA=D0=B8=D0=BD?= Date: Fri, 13 Mar 2020 10:04:11 +0300 Subject: [PATCH 6/7] Changes to compile on Qt 5.14.1 --- src/xlsx/xlsxworksheet_p.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/xlsx/xlsxworksheet_p.h b/src/xlsx/xlsxworksheet_p.h index a7caa59..4762c61 100644 --- a/src/xlsx/xlsxworksheet_p.h +++ b/src/xlsx/xlsxworksheet_p.h @@ -48,6 +48,7 @@ #include #include #include +#include class QXmlStreamWriter; class QXmlStreamReader; From da6437cf5dde6a4a0895d1f46f4beb361779ba0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=92=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA=D0=B8=D0=BD?= Date: Mon, 6 Feb 2023 17:34:26 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D1=8F=20=D1=81?= =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xlsx/xlsxworksheet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 89eb513..bd72489 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -1389,9 +1389,11 @@ void WorksheetPrivate::saveXmlCellData(QXmlStreamWriter &writer, int row, int co sst_idx = sharedStrings()->getSharedStringIndex(cell->d_ptr->richString); else sst_idx = sharedStrings()->getSharedStringIndex(cell->value().toString()); - - writer.writeAttribute(QStringLiteral("t"), QStringLiteral("s")); - writer.writeTextElement(QStringLiteral("v"), QString::number(sst_idx)); + + if (sst_idx >= 0) { + writer.writeAttribute(QStringLiteral("t"), QStringLiteral("s")); + writer.writeTextElement(QStringLiteral("v"), QString::number(sst_idx)); + } } else if (cell->cellType() == Cell::InlineStringType) { writer.writeAttribute(QStringLiteral("t"), QStringLiteral("inlineStr")); writer.writeStartElement(QStringLiteral("is"));