Browse Source

Don't omit default attribute fontId/fillId/borderId

master
Debao Zhang 11 years ago
parent
commit
2ec533df7c
  1. 22
      src/xlsx/xlsxformat.cpp
  2. 12
      src/xlsx/xlsxstyles.cpp
  3. 3
      tests/auto/styles/tst_stylestest.cpp

22
src/xlsx/xlsxformat.cpp

@ -33,9 +33,9 @@ QT_BEGIN_NAMESPACE_XLSX
FormatPrivate::FormatPrivate() FormatPrivate::FormatPrivate()
: dirty(true) : dirty(true)
, font_dirty(true), font_index_valid(false), font_index(-1) , font_dirty(true), font_index_valid(false), font_index(0)
, fill_dirty(true), fill_index_valid(false), fill_index(-1) , fill_dirty(true), fill_index_valid(false), fill_index(0)
, border_dirty(true), border_index_valid(false), border_index(-1) , border_dirty(true), border_index_valid(false), border_index(0)
, xf_index(-1), xf_indexValid(false) , xf_index(-1), xf_indexValid(false)
, is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false) , is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false)
, theme(0) , theme(0)
@ -215,7 +215,7 @@ Format::~Format()
*/ */
int Format::numberFormatIndex() const 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()) if (fontIndexValid())
return d->font_index; return d->font_index;
return -1; return 0;
} }
/*! /*!
@ -884,7 +884,9 @@ bool Format::borderIndexValid() const
*/ */
int Format::borderIndex() 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) void Format::setBorderIndex(int index)
{ {
d->border_index = index; d->border_index = index;
d->border_index_valid = true;
} }
/*! \internal /*! \internal
@ -1000,9 +1003,9 @@ bool Format::fillIndexValid() const
*/ */
int Format::fillIndex() const int Format::fillIndex() const
{ {
if (!d) if (fillIndexValid())
return 0; return d->fill_index;
return d->fill_index; return 0;
} }
/*! /*!
@ -1011,6 +1014,7 @@ int Format::fillIndex() const
void Format::setFillIndex(int index) void Format::setFillIndex(int index)
{ {
d->fill_index = index; d->fill_index = index;
d->fill_index_valid = true;
} }
/*! /*!

12
src/xlsx/xlsxstyles.cpp

@ -571,14 +571,10 @@ void Styles::writeCellXfs(QXmlStreamWriter &writer)
foreach (const Format &format, m_xf_formatsList) { foreach (const Format &format, m_xf_formatsList) {
int xf_id = 0; int xf_id = 0;
writer.writeStartElement(QStringLiteral("xf")); writer.writeStartElement(QStringLiteral("xf"));
if (format.hasNumFmtData()) writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(format.numberFormatIndex()));
writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(format.numberFormatIndex())); writer.writeAttribute(QStringLiteral("fontId"), QString::number(format.fontIndex()));
if (format.hasFontData()) writer.writeAttribute(QStringLiteral("fillId"), QString::number(format.fillIndex()));
writer.writeAttribute(QStringLiteral("fontId"), QString::number(format.fontIndex())); writer.writeAttribute(QStringLiteral("borderId"), QString::number(format.borderIndex()));
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("xfId"), QString::number(xf_id)); writer.writeAttribute(QStringLiteral("xfId"), QString::number(xf_id));
if (format.hasNumFmtData()) if (format.hasNumFmtData())
writer.writeAttribute(QStringLiteral("applyNumberFormat"), QStringLiteral("1")); writer.writeAttribute(QStringLiteral("applyNumberFormat"), QStringLiteral("1"));

3
tests/auto/styles/tst_stylestest.cpp

@ -35,8 +35,7 @@ void StylesTest::testEmptyStyle()
QXlsx::Styles styles; QXlsx::Styles styles;
QByteArray xmlData = styles.saveToXmlData(); QByteArray xmlData = styles.saveToXmlData();
// QVERIFY2(xmlData.contains("<cellXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/></cellXfs>"), "Must have one cell style"); QVERIFY2(xmlData.contains("<cellXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/></cellXfs>"), "Must have one cell style");
QVERIFY2(xmlData.contains("<cellXfs count=\"1\"><xf xfId=\"0\"/></cellXfs>"), "Must have one cell style");
QVERIFY2(xmlData.contains("<border><left/><right/><top/><bottom/><diagonal/></border>"), "Excel don't simply generate <border/>, through it works"); QVERIFY2(xmlData.contains("<border><left/><right/><top/><bottom/><diagonal/></border>"), "Excel don't simply generate <border/>, through it works");
} }

Loading…
Cancel
Save