diff --git a/src/xlsx/xlsxformat.cpp b/src/xlsx/xlsxformat.cpp index 9e4acda..8d81c70 100755 --- a/src/xlsx/xlsxformat.cpp +++ b/src/xlsx/xlsxformat.cpp @@ -33,9 +33,9 @@ QT_BEGIN_NAMESPACE_XLSX FormatPrivate::FormatPrivate() : dirty(true) - , font_dirty(true), font_index_valid(false), font_index(-1) - , fill_dirty(true), fill_index_valid(false), fill_index(-1) - , border_dirty(true), border_index_valid(false), border_index(-1) + , font_dirty(true), font_index_valid(false), font_index(0) + , fill_dirty(true), fill_index_valid(false), fill_index(0) + , border_dirty(true), border_index_valid(false), border_index(0) , xf_index(-1), xf_indexValid(false) , is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false) , theme(0) @@ -215,7 +215,7 @@ Format::~Format() */ int Format::numberFormatIndex() const { - return intProperty(FormatPrivate::P_NumFmt_Id); + return intProperty(FormatPrivate::P_NumFmt_Id, 0); } /*! @@ -477,7 +477,7 @@ int Format::fontIndex() const if (fontIndexValid()) return d->font_index; - return -1; + return 0; } /*! @@ -884,7 +884,9 @@ bool Format::borderIndexValid() const */ int Format::borderIndex() const { - return d->border_index; + if (borderIndexValid()) + return d->border_index; + return 0; } /*! @@ -893,6 +895,7 @@ int Format::borderIndex() const void Format::setBorderIndex(int index) { d->border_index = index; + d->border_index_valid = true; } /*! \internal @@ -1000,9 +1003,9 @@ bool Format::fillIndexValid() const */ int Format::fillIndex() const { - if (!d) - return 0; - return d->fill_index; + if (fillIndexValid()) + return d->fill_index; + return 0; } /*! @@ -1011,6 +1014,7 @@ int Format::fillIndex() const void Format::setFillIndex(int index) { d->fill_index = index; + d->fill_index_valid = true; } /*! diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index 836d0c1..d0a1f31 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/src/xlsx/xlsxstyles.cpp @@ -571,14 +571,10 @@ void Styles::writeCellXfs(QXmlStreamWriter &writer) foreach (const Format &format, m_xf_formatsList) { int xf_id = 0; writer.writeStartElement(QStringLiteral("xf")); - if (format.hasNumFmtData()) - writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(format.numberFormatIndex())); - if (format.hasFontData()) - writer.writeAttribute(QStringLiteral("fontId"), QString::number(format.fontIndex())); - if (format.hasFillData()) - writer.writeAttribute(QStringLiteral("fillId"), QString::number(format.fillIndex())); - if (format.hasBorderData()) - writer.writeAttribute(QStringLiteral("borderId"), QString::number(format.borderIndex())); + writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(format.numberFormatIndex())); + writer.writeAttribute(QStringLiteral("fontId"), QString::number(format.fontIndex())); + writer.writeAttribute(QStringLiteral("fillId"), QString::number(format.fillIndex())); + writer.writeAttribute(QStringLiteral("borderId"), QString::number(format.borderIndex())); writer.writeAttribute(QStringLiteral("xfId"), QString::number(xf_id)); if (format.hasNumFmtData()) writer.writeAttribute(QStringLiteral("applyNumberFormat"), QStringLiteral("1")); diff --git a/tests/auto/styles/tst_stylestest.cpp b/tests/auto/styles/tst_stylestest.cpp index 170e0f8..ae49317 100644 --- a/tests/auto/styles/tst_stylestest.cpp +++ b/tests/auto/styles/tst_stylestest.cpp @@ -35,8 +35,7 @@ void StylesTest::testEmptyStyle() QXlsx::Styles styles; QByteArray xmlData = styles.saveToXmlData(); -// QVERIFY2(xmlData.contains(""), "Must have one cell style"); - QVERIFY2(xmlData.contains(""), "Must have one cell style"); + QVERIFY2(xmlData.contains(""), "Must have one cell style"); QVERIFY2(xmlData.contains(""), "Excel don't simply generate , through it works"); }