From 84ca047e7f96d429ed59da15458ef8fae46554b4 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 25 Oct 2013 16:32:43 +0800 Subject: [PATCH] Fix Styles::readNumFmts() bug --- src/xlsx/xlsxstyles.cpp | 3 +++ tests/auto/document/tst_documenttest.cpp | 12 ++++++------ tests/auto/styles/tst_stylestest.cpp | 5 +++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index 1a2cb7d..954821c 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/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; } diff --git a/tests/auto/document/tst_documenttest.cpp b/tests/auto/document/tst_documenttest.cpp index fafc404..5ee587d 100644 --- a/tests/auto/document/tst_documenttest.cpp +++ b/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()<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()<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"); diff --git a/tests/auto/styles/tst_stylestest.cpp b/tests/auto/styles/tst_stylestest.cpp index e173858..781875e 100644 --- a/tests/auto/styles/tst_stylestest.cpp +++ b/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)