From bbf3ffd79dbdebc08ea82f02c0375051bc7319aa Mon Sep 17 00:00:00 2001 From: eho Date: Fri, 14 Mar 2014 10:24:30 +0100 Subject: [PATCH] Fixed a bug where row formatting was not saved when row contained no filled cells. --- src/xlsx/xlsxworksheet.cpp | 63 +++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index ee61edf..b8d7a82 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -1289,51 +1289,44 @@ void WorksheetPrivate::saveXmlSheetData(QXmlStreamWriter &writer) const if (row_spans.contains(span_index)) span = row_spans[span_index]; - if (cellTable.contains(row_num)) { - writer.writeStartElement(QStringLiteral("row")); - writer.writeAttribute(QStringLiteral("r"), QString::number(row_num)); - - if (!span.isEmpty()) - writer.writeAttribute(QStringLiteral("spans"), span); + writer.writeStartElement(QStringLiteral("row")); + writer.writeAttribute(QStringLiteral("r"), QString::number(row_num)); - if (rowsInfo.contains(row_num)) { - QSharedPointer rowInfo = rowsInfo[row_num]; - if (!rowInfo->format.isEmpty()) { - writer.writeAttribute(QStringLiteral("s"), QString::number(rowInfo->format.xfIndex())); - writer.writeAttribute(QStringLiteral("customFormat"), QStringLiteral("1")); - } - //!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("customHeight"), QStringLiteral("1")); - qDebug() << "custom height: " << rowInfo->height; - } else { - writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("0")); - qDebug() << "no height: "; - } + if (!span.isEmpty()) + writer.writeAttribute(QStringLiteral("spans"), span); - - - if (rowInfo->hidden) - writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1")); - if (rowInfo->outlineLevel > 0) - writer.writeAttribute(QStringLiteral("outlineLevel"), QString::number(rowInfo->outlineLevel)); - if (rowInfo->collapsed) - writer.writeAttribute(QStringLiteral("collapsed"), QStringLiteral("1")); + if (rowsInfo.contains(row_num)) { + QSharedPointer rowInfo = rowsInfo[row_num]; + if (!rowInfo->format.isEmpty()) { + writer.writeAttribute(QStringLiteral("s"), QString::number(rowInfo->format.xfIndex())); + writer.writeAttribute(QStringLiteral("customFormat"), QStringLiteral("1")); + } + //!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("customHeight"), QStringLiteral("1")); + } else { + writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("0")); } + if (rowInfo->hidden) + writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1")); + if (rowInfo->outlineLevel > 0) + writer.writeAttribute(QStringLiteral("outlineLevel"), QString::number(rowInfo->outlineLevel)); + if (rowInfo->collapsed) + writer.writeAttribute(QStringLiteral("collapsed"), QStringLiteral("1")); + } + + //Write cell data if row contains filled cells + if (cellTable.contains(row_num)) { for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn(); col_num++) { if (cellTable[row_num].contains(col_num)) { saveXmlCellData(writer, row_num, col_num, cellTable[row_num][col_num]); } } - writer.writeEndElement(); //row - } else if (comments.contains(row_num)){ - - } else { - } + writer.writeEndElement(); //row } }