From ab5ad121fe8b04bb136f61078cd5cab72a708d1a Mon Sep 17 00:00:00 2001 From: Look Skyworker Date: Thu, 5 Oct 2017 22:57:10 +0900 Subject: [PATCH] test --- QXlsx/source/xlsxcell.cpp | 19 +++++++++++++++++-- QXlsx/source/xlsxworksheet.cpp | 19 +++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/QXlsx/source/xlsxcell.cpp b/QXlsx/source/xlsxcell.cpp index 286018d..7afa6ef 100644 --- a/QXlsx/source/xlsxcell.cpp +++ b/QXlsx/source/xlsxcell.cpp @@ -184,10 +184,25 @@ CellFormula Cell::formula() const bool Cell::isDateTime() const { Q_D(const Cell); - if (d->cellType == NumberType && d->value.toDouble() >=0 - && d->format.isValid() && d->format.isDateTimeFormat()) { + + Cell::CellType cellType = d->cellType; + double dValue = d->value.toDouble(); + QString strValue = d->value.toString().toUtf8(); + bool isValidFormat = d->format.isValid(); + bool isDateTimeFormat = d->format.isDateTimeFormat(); + + // NOTICE: google spreadsheet data is not adoptable. + // cell style(10): cellType is SharedStringType. strValue is '1900. 1. 9'. + // cell style(12): cellType is SharedStringType. strValue is '1900. 1. 11 AM 12:00:00'. + + if ( cellType == NumberType && + dValue >= 0 && + isValidFormat && + isDateTimeFormat ) + { return true; } + return false; } diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index 51244fa..aa0c61f 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -1941,7 +1941,7 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) } } - else if (reader.name() == QLatin1String("c")) + else if (reader.name() == QLatin1String("c")) // Cell { //Cell QXmlStreamAttributes attributes = reader.attributes(); @@ -1950,10 +1950,12 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) //get format Format format; - if (attributes.hasAttribute(QLatin1String("s"))) + int styleIndex = -1; + if (attributes.hasAttribute(QLatin1String("s"))) // Style { //"s" == style index int idx = attributes.value(QLatin1String("s")).toString().toInt(); + styleIndex = idx; format = workbook->styles()->xfFormat(idx); ////Empty format exists in styles xf table of real .xlsx files, see issue #65. @@ -1962,11 +1964,20 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) } Cell::CellType cellType = Cell::NumberType; - if (attributes.hasAttribute(QLatin1String("t"))) + if (attributes.hasAttribute(QLatin1String("t"))) // Type { QString typeString = attributes.value(QLatin1String("t")).toString(); if (typeString == QLatin1String("s")) - cellType = Cell::SharedStringType; + { + cellType = Cell::SharedStringType; + + // NOTICE: somtimes 's' is not string type. it may be date-time type. + if ( styleIndex == 10 || + styleIndex == 12 ) + { + cellType = Cell::NumberType; + } + } else if (typeString == QLatin1String("inlineStr")) cellType = Cell::InlineStringType; else if (typeString == QLatin1String("str"))