Add QDateTime support for QXlsx::Cell
This commit is contained in:
+2
-1
@@ -8,4 +8,5 @@ SUBDIRS=\
|
||||
propsapp \
|
||||
document \
|
||||
sharedstrings \
|
||||
styles
|
||||
styles \
|
||||
format
|
||||
|
||||
@@ -20,6 +20,7 @@ private Q_SLOTS:
|
||||
void testReadWriteBool();
|
||||
void testReadWriteBlank();
|
||||
void testReadWriteFormula();
|
||||
void testReadWriteDateTime();
|
||||
};
|
||||
|
||||
DocumentTest::DocumentTest()
|
||||
@@ -156,6 +157,46 @@ void DocumentTest::testReadWriteFormula()
|
||||
QFile::remove("test.xlsx");
|
||||
}
|
||||
|
||||
void DocumentTest::testReadWriteDateTime()
|
||||
{
|
||||
Document xlsx1;
|
||||
QDateTime dt(QDate(2012, 11, 12), QTime(6, 0), Qt::UTC);
|
||||
|
||||
xlsx1.write("A1", dt);
|
||||
|
||||
Format *format = xlsx1.createFormat();
|
||||
format->setFontColor(Qt::blue);
|
||||
format->setBorderStyle(Format::BorderDashDotDot);
|
||||
format->setFillPattern(Format::PatternSolid);
|
||||
xlsx1.write("A2", dt, format);
|
||||
|
||||
Format *format3 = xlsx1.createFormat();
|
||||
format3->setNumberFormat("dd/mm/yyyy");
|
||||
xlsx1.write("A3", dt, format3);
|
||||
|
||||
xlsx1.saveAs("test.xlsx");
|
||||
|
||||
Document xlsx2("test.xlsx");
|
||||
|
||||
QCOMPARE(xlsx2.cellAt("A1")->dataType(), Cell::Numeric);
|
||||
QCOMPARE(xlsx2.cellAt("A1")->isDateTime(), true);
|
||||
QCOMPARE(xlsx2.cellAt("A1")->dateTime(), dt);
|
||||
|
||||
QCOMPARE(xlsx2.cellAt("A2")->dataType(), Cell::Numeric);
|
||||
// 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"));
|
||||
|
||||
QFile::remove("test.xlsx");
|
||||
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(DocumentTest)
|
||||
|
||||
#include "tst_documenttest.moc"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
QT += testlib xlsx # xlsx-private
|
||||
CONFIG += testcase
|
||||
DEFINES += XLSX_TEST
|
||||
|
||||
TARGET = tst_format
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += tst_formattest.cpp
|
||||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "xlsxformat.h"
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
|
||||
QTXLSX_USE_NAMESPACE
|
||||
|
||||
class FormatTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FormatTest();
|
||||
|
||||
private Q_SLOTS:
|
||||
void testDateTimeFormat();
|
||||
void testDateTimeFormat_data();
|
||||
};
|
||||
|
||||
FormatTest::FormatTest()
|
||||
{
|
||||
}
|
||||
|
||||
void FormatTest::testDateTimeFormat()
|
||||
{
|
||||
QFETCH(QString, data);
|
||||
QFETCH(bool, res);
|
||||
|
||||
Format fmt;
|
||||
fmt.setNumberFormat(data);
|
||||
|
||||
QCOMPARE(fmt.isDateTimeFormat(), res);
|
||||
}
|
||||
|
||||
void FormatTest::testDateTimeFormat_data()
|
||||
{
|
||||
QTest::addColumn<QString>("data");
|
||||
QTest::addColumn<bool>("res");
|
||||
|
||||
QTest::newRow("0") << QString("yyyy-mm-dd")<<true;
|
||||
QTest::newRow("1") << QString("m/d/yy")<<true;
|
||||
QTest::newRow("2") << QString("h:mm AM/PM")<<true;
|
||||
QTest::newRow("3") << QString("m/d/yy h:mm")<<true;
|
||||
QTest::newRow("4") << QString("[h]:mm:ss")<<true;
|
||||
QTest::newRow("5") << QString("[h]")<<true;
|
||||
QTest::newRow("6") << QString("[m]")<<true;
|
||||
|
||||
QTest::newRow("20") << QString("[Red]#,##0 ;[Yellow](#,##0)")<<false;
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(FormatTest)
|
||||
|
||||
#include "tst_formattest.moc"
|
||||
@@ -18,6 +18,7 @@ private Q_SLOTS:
|
||||
void testAddFormat2();
|
||||
void testSolidFillBackgroundColor();
|
||||
|
||||
void testReadNumFmts();
|
||||
void testReadFonts();
|
||||
void testReadFills();
|
||||
void testReadBorders();
|
||||
@@ -128,6 +129,21 @@ void StylesTest::testReadBorders()
|
||||
QCOMPARE(styles.m_bordersList.size(), 2);
|
||||
}
|
||||
|
||||
void StylesTest::testReadNumFmts()
|
||||
{
|
||||
QByteArray xmlData ="<numFmts count=\"2\">"
|
||||
"<numFmt numFmtId=\"164\" formatCode=\"yyyy-mm-ddThh:mm:ss\"/>"
|
||||
"<numFmt numFmtId=\"165\" formatCode=\"dd/mm/yyyy\"/>"
|
||||
"</numFmts>";
|
||||
|
||||
QXlsx::Styles styles(true);
|
||||
QXlsx::XmlStreamReader reader(xmlData);
|
||||
reader.readNextStartElement();//So current node is numFmts
|
||||
styles.readNumFmts(reader);
|
||||
|
||||
QCOMPARE(styles.m_customNumFmts.size(), 2);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(StylesTest)
|
||||
|
||||
#include "tst_stylestest.moc"
|
||||
|
||||
Reference in New Issue
Block a user