-
-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with QDateTime handling #50
Labels
Comments
1️⃣ Note
2️⃣ First examplecodeusing namespace QXlsx;
Document doc;
doc.addSheet("TestWorksheet");
QVariant expected = QDateTime::currentDateTimeUtc();
assert(doc.write("A1", expected));
QVariant actual;
auto cell = doc.cellAt("A1"); // get cell pointer.
if ( cell != nullptr)
actual = cell->readValue();
qDebug() << (actual == expected ? "Values are the same" : "Values are Not the same");
qDebug() << "Expected:" << expected.toString() << expected.type();
qDebug() << "Actual:" << actual.toString() << actual.type();
doc.saveAs("EA.xlsx"); output
Open file in Excel (EA.xlsx)3️⃣ Second examplecodeQString fileName = QUuid::createUuid().toString() + ".xlsx";
QFile::remove(fileName);
auto docW = new QXlsx::Document(fileName);
docW->addSheet("TestWorksheet");
QVariant expected = QDateTime::currentDateTimeUtc();
assert(docW->write("A1", expected));
docW->save();
delete docW;
auto docR = new QXlsx::Document(fileName);
docR->load();
QVariant actual;
auto cell = docR->cellAt("A1"); // get cell pointer.
if ( cell != nullptr)
actual = cell->readValue();
auto expectedTime = expected.toDateTime();
auto actualTime = actual.toDateTime();
qDebug() << (actualTime == expectedTime ? "Values are the same" : "Values are Not the same");
qDebug() << "Expected:" << expectedTime.toString(Qt::DateFormat::ISODate);
qDebug() << "Actual:" << actualTime.toString(Qt::DateFormat::ISODate);
delete docR;
QFile::remove(fileName); output
|
I fixed some code. aaebf96 Try the test. |
More example
using namespace QXlsx;
Document doc;
doc.write( "A1", QVariant(QDateTime::currentDateTimeUtc()) );
doc.write( "A2", QVariant(double(10.5)) );
doc.write( "A3", QVariant(QDate(2019, 10, 9)) );
doc.write( "A4", QVariant(QTime(10, 9, 5)) );
doc.write( "A5", QVariant((int) 40000) );
qDebug() << "doc.read()";
qDebug() << doc.read( 1, 1 ).type() << doc.read( 1, 1 );
qDebug() << doc.read( 2, 1 ).type() << doc.read( 2, 1 );
qDebug() << doc.read( 3, 1 ).type() << doc.read( 3, 1 );
qDebug() << doc.read( 4, 1 ).type() << doc.read( 4, 1 );
qDebug() << doc.read( 5, 1 ).type() << doc.read( 5, 1 );
qDebug() << "\n";
qDebug() << "doc.cellAt()->value()";
qDebug() << doc.cellAt( 1, 1 )->value().type() << doc.cellAt( 1, 1 )->value();
qDebug() << doc.cellAt( 2, 1 )->value().type() << doc.cellAt( 2, 1 )->value();
qDebug() << doc.cellAt( 3, 1 )->value().type() << doc.cellAt( 3, 1 )->value();
qDebug() << doc.cellAt( 4, 1 )->value().type() << doc.cellAt( 4, 1 )->value();
qDebug() << doc.cellAt( 5, 1 )->value().type() << doc.cellAt( 5, 1 )->value();
doc.saveAs("datetime.xlsx");
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I have identified some possible issues with QDateTime handling. In the following test code I can construct a document in memory and write/read strings, but for QDateTime the values are different (it works fine for strings):
This is not an issue for me as I'm writing the document only, but it did throw me a bit.
Also note in the following test code I write to a file and then read it back again but the QDateTime is now empty:
I tracked this issue down the Cell::dateTime() method where dValue is always 0 because the variant is identified as a QDateTime and not a number.
It seems that QDateTime handling is broken; obviously it can be worked around by converting to strings, but this is a pain if serializing a QObject.
Thank you.
Kevin
The text was updated successfully, but these errors were encountered: