Improve the QDate support
This commit is contained in:
@@ -77,7 +77,7 @@ QDateTime datetimeFromNumber(double num, bool is1904)
|
||||
if (!is1904 && num > 60)
|
||||
num = num - 1;
|
||||
|
||||
qint64 msecs = static_cast<qint64>(num * 1000*60*60*24.0);
|
||||
qint64 msecs = static_cast<qint64>(num * 1000*60*60*24.0 + 0.5);
|
||||
QDateTime epoch(is1904 ? QDate(1904, 1, 1): QDate(1899, 12, 31), QTime(0,0));
|
||||
|
||||
return epoch.addMSecs(msecs);
|
||||
|
||||
@@ -53,7 +53,7 @@ WorkbookPrivate::WorkbookPrivate(Workbook *q) :
|
||||
|
||||
strings_to_numbers_enabled = false;
|
||||
date1904 = false;
|
||||
defaultDateFormat = QStringLiteral("yyyy-mm-ddThh:mm:ss");
|
||||
defaultDateFormat = QStringLiteral("yyyy-mm-dd");
|
||||
activesheet = 0;
|
||||
firstsheet = 0;
|
||||
table_count = 0;
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE_XLSX
|
||||
|
||||
@@ -516,6 +517,8 @@ QVariant Worksheet::read(int row, int column) const
|
||||
QDateTime dt = cell->dateTime();
|
||||
if (val < 1)
|
||||
return dt.time();
|
||||
if (fmod(val, 1.0) < 1.0/(1000*60*60*24)) //integer
|
||||
return dt.date();
|
||||
return dt;
|
||||
}
|
||||
return cell->value();
|
||||
@@ -848,8 +851,8 @@ int Worksheet::writeDateTime(int row, int column, const QDateTime &dt, const For
|
||||
if (d->checkDimensions(row, column))
|
||||
return -1;
|
||||
|
||||
Format fmt = format;
|
||||
if (!fmt.isValid())
|
||||
Format fmt = format.isValid() ? format : d->cellFormat(row, column);
|
||||
if (!fmt.isValid() || !fmt.isDateTimeFormat())
|
||||
fmt.setNumberFormat(d->workbook->defaultDateFormat());
|
||||
d->workbook->styles()->addXfFormat(fmt);
|
||||
|
||||
@@ -882,8 +885,8 @@ int Worksheet::writeTime(int row, int column, const QTime &t, const Format &form
|
||||
if (d->checkDimensions(row, column))
|
||||
return -1;
|
||||
|
||||
Format fmt = format;
|
||||
if (!fmt.isValid())
|
||||
Format fmt = format.isValid() ? format : d->cellFormat(row, column);
|
||||
if (!fmt.isValid() || !fmt.isDateTimeFormat())
|
||||
fmt.setNumberFormat(QStringLiteral("hh:mm:ss"));
|
||||
d->workbook->styles()->addXfFormat(fmt);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user