|
|
@ -21,6 +21,7 @@ private Q_SLOTS: |
|
|
|
void testReadWriteBlank(); |
|
|
|
void testReadWriteFormula(); |
|
|
|
void testReadWriteDateTime(); |
|
|
|
void testReadWriteDate(); |
|
|
|
void testReadWriteTime(); |
|
|
|
}; |
|
|
|
|
|
|
@ -193,7 +194,7 @@ void DocumentTest::testReadWriteDateTime() |
|
|
|
format3.setNumberFormat("dd/mm/yyyy"); |
|
|
|
xlsx1.write("A3", dt, format3); |
|
|
|
|
|
|
|
xlsx1.write("A4", "2013-12-14"); //Auto convert to QDateTime, by QVariant
|
|
|
|
xlsx1.write("A4", "2013-12-14T12:30"); //Auto convert to QDateTime, by QVariant
|
|
|
|
|
|
|
|
xlsx1.saveAs(&device); |
|
|
|
|
|
|
@ -202,21 +203,72 @@ void DocumentTest::testReadWriteDateTime() |
|
|
|
QCOMPARE(xlsx2.cellAt("A1")->dataType(), Cell::Numeric); |
|
|
|
QCOMPARE(xlsx2.cellAt("A1")->isDateTime(), true); |
|
|
|
QCOMPARE(xlsx2.cellAt("A1")->dateTime(), dt); |
|
|
|
QVERIFY(xlsx2.read("A1").userType() == QMetaType::QDateTime); |
|
|
|
|
|
|
|
QCOMPARE(xlsx2.cellAt("A2")->dataType(), Cell::Numeric); |
|
|
|
// QCOMPARE(xlsx2.cellAt("A2")->isDateTime(), true);
|
|
|
|
// QCOMPARE(xlsx2.cellAt("A2")->dateTime(), dt);
|
|
|
|
QCOMPARE(xlsx2.cellAt("A2")->isDateTime(), true); |
|
|
|
QCOMPARE(xlsx2.cellAt("A2")->dateTime(), dt); |
|
|
|
QVERIFY(xlsx2.read("A2").userType() == QMetaType::QDateTime); |
|
|
|
|
|
|
|
QCOMPARE(xlsx2.cellAt("A3")->dataType(), Cell::Numeric); |
|
|
|
QVERIFY(xlsx2.cellAt("A3")->format().isValid()); |
|
|
|
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("A4")->dataType(), Cell::Numeric); |
|
|
|
QCOMPARE(xlsx2.cellAt("A4")->isDateTime(), true); |
|
|
|
QCOMPARE(xlsx2.cellAt("A4")->dateTime(), QDateTime(QDate(2013,12,14), QTime(12, 30))); |
|
|
|
QVERIFY(xlsx2.read("A4").userType() == QMetaType::QDateTime); |
|
|
|
} |
|
|
|
|
|
|
|
void DocumentTest::testReadWriteDate() |
|
|
|
{ |
|
|
|
QBuffer device; |
|
|
|
device.open(QIODevice::WriteOnly); |
|
|
|
|
|
|
|
Document xlsx1; |
|
|
|
QDate d(2012, 11, 12); |
|
|
|
|
|
|
|
xlsx1.write("A1", d); |
|
|
|
|
|
|
|
Format format; |
|
|
|
format.setFontColor(Qt::blue); |
|
|
|
format.setBorderStyle(Format::BorderDashDotDot); |
|
|
|
format.setFillPattern(Format::PatternSolid); |
|
|
|
xlsx1.write("A2", d, format); |
|
|
|
|
|
|
|
Format format3; |
|
|
|
format3.setNumberFormat("dd/mm/yyyy"); |
|
|
|
xlsx1.write("A3", d, format3); |
|
|
|
|
|
|
|
xlsx1.write("A4", "2013-12-14"); //Auto convert to QDateTime, by QVariant
|
|
|
|
|
|
|
|
xlsx1.saveAs(&device); |
|
|
|
|
|
|
|
device.open(QIODevice::ReadOnly); |
|
|
|
Document xlsx2(&device); |
|
|
|
QCOMPARE(xlsx2.cellAt("A1")->dataType(), Cell::Numeric); |
|
|
|
QCOMPARE(xlsx2.cellAt("A1")->isDateTime(), true); |
|
|
|
QVERIFY(xlsx2.read("A1").userType() == QMetaType::QDate); |
|
|
|
QCOMPARE(xlsx2.read("A1").toDate(), d); |
|
|
|
|
|
|
|
QCOMPARE(xlsx2.cellAt("A2")->dataType(), Cell::Numeric); |
|
|
|
QCOMPARE(xlsx2.cellAt("A2")->isDateTime(), true); |
|
|
|
QVERIFY(xlsx2.read("A2").userType() == QMetaType::QDate); |
|
|
|
|
|
|
|
QCOMPARE(xlsx2.cellAt("A3")->dataType(), Cell::Numeric); |
|
|
|
QVERIFY(xlsx2.cellAt("A3")->format().isValid()); |
|
|
|
QCOMPARE(xlsx2.cellAt("A3")->isDateTime(), true); |
|
|
|
QCOMPARE(xlsx2.cellAt("A3")->format().numberFormat(), QString("dd/mm/yyyy")); |
|
|
|
QVERIFY(xlsx2.read("A3").userType() == QMetaType::QDate); |
|
|
|
QCOMPARE(xlsx2.read("A3").toDate(), d); |
|
|
|
|
|
|
|
QCOMPARE(xlsx2.cellAt("A4")->dataType(), Cell::Numeric); |
|
|
|
QCOMPARE(xlsx2.cellAt("A4")->isDateTime(), true); |
|
|
|
QCOMPARE(xlsx2.cellAt("A4")->dateTime(), QDateTime(QDate(2013,12,14))); |
|
|
|
QVERIFY(xlsx2.read("A4").userType() == QMetaType::QDate); |
|
|
|
QCOMPARE(xlsx2.read("A4").toDate(), QDate(2013,12,14)); |
|
|
|
} |
|
|
|
|
|
|
|
void DocumentTest::testReadWriteTime() |
|
|
@ -238,8 +290,8 @@ void DocumentTest::testReadWriteTime() |
|
|
|
|
|
|
|
QCOMPARE(xlsx2.cellAt("A2")->dataType(), Cell::Numeric); |
|
|
|
QCOMPARE(xlsx2.cellAt("A2")->isDateTime(), true); |
|
|
|
qDebug()<<xlsx2.cellAt("A2")->value().toDouble(); |
|
|
|
//QCOMPARE(xlsx2.read("A2").toTime(), QTime(1, 22)); //01:21:59.999 ???
|
|
|
|
QVERIFY(xlsx2.read("A2").userType() == QMetaType::QTime); |
|
|
|
QCOMPARE(xlsx2.read("A2").toTime(), QTime(1, 22)); |
|
|
|
} |
|
|
|
|
|
|
|
QTEST_APPLESS_MAIN(DocumentTest) |
|
|
|