Browse Source

Fix Styles::readNumFmts() bug

master
Debao Zhang 11 years ago
parent
commit
84ca047e7f
  1. 3
      src/xlsx/xlsxstyles.cpp
  2. 12
      tests/auto/document/tst_documenttest.cpp
  3. 5
      tests/auto/styles/tst_stylestest.cpp

3
src/xlsx/xlsxstyles.cpp

@ -547,6 +547,9 @@ bool Styles::readNumFmts(XmlStreamReader &reader)
fmt->formatString = attributes.value(QLatin1String("formatCode")).toString();
m_customNumFmts.append(fmt);
m_customNumFmtsHash.insert(fmt->formatString, fmt);
while (!(reader.name() == QLatin1String("numFmt") && reader.tokenType() == QXmlStreamReader::EndElement))
reader.readNextStartElement();
}
return true;
}

12
tests/auto/document/tst_documenttest.cpp

@ -186,12 +186,12 @@ void DocumentTest::testReadWriteDateTime()
// QCOMPARE(xlsx2.cellAt("A2")->isDateTime(), true);
// QCOMPARE(xlsx2.cellAt("A2")->dateTime(), dt);
// QCOMPARE(xlsx2.cellAt("A3")->dataType(), Cell::Numeric);
// QVERIFY(xlsx2.cellAt("A3")->format()!=0);
// qDebug()<<xlsx2.cellAt("A3")->format()->numberFormat();
// QCOMPARE(xlsx2.cellAt("A3")->isDateTime(), true);
// QCOMPARE(xlsx2.cellAt("A3")->dateTime(), dt);
// QCOMPARE(xlsx2.cellAt("A3")->format()->numberFormat(), QString("dd/mm/yyyy"));
QCOMPARE(xlsx2.cellAt("A3")->dataType(), Cell::Numeric);
QVERIFY(xlsx2.cellAt("A3")->format()!=0);
qDebug()<<xlsx2.cellAt("A3")->format()->numberFormat();
QCOMPARE(xlsx2.cellAt("A3")->isDateTime(), true);
QCOMPARE(xlsx2.cellAt("A3")->dateTime(), dt);
QCOMPARE(xlsx2.cellAt("A3")->format()->numberFormat(), QString("dd/mm/yyyy"));
QFile::remove("test.xlsx");

5
tests/auto/styles/tst_stylestest.cpp

@ -142,6 +142,11 @@ void StylesTest::testReadNumFmts()
styles.readNumFmts(reader);
QCOMPARE(styles.m_customNumFmts.size(), 2);
QCOMPARE(styles.m_customNumFmts[0]->formatIndex, 164);
QCOMPARE(styles.m_customNumFmts[0]->formatString, QStringLiteral("yyyy-mm-ddThh:mm:ss"));
QCOMPARE(styles.m_customNumFmts[1]->formatIndex, 165);
QCOMPARE(styles.m_customNumFmts[1]->formatString, QStringLiteral("dd/mm/yyyy"));
}
QTEST_APPLESS_MAIN(StylesTest)

Loading…
Cancel
Save