1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-16 04:42:53 +08:00

testing cell style

This commit is contained in:
Look Skyworker 2017-10-06 17:48:52 +09:00
parent b259f95120
commit acc9e99bbc
4 changed files with 81 additions and 46 deletions

View File

@ -131,13 +131,15 @@ QVariant Cell::readValue() const
return ret; return ret;
} }
if (fmod(val, 1.0) < 1.0 / (1000 * 60 * 60 * 24)) double dFmod = fmod(val, double(1.0));
double dRValue = 1.0 / (1000 * 60 * 60 * 24);
if ( dFmod < dRValue )
{ {
ret = dt.date(); // it's date type ret = dt.date(); // it's date type
return ret; return ret;
} }
return ret; return ret; // or. ...?
} }
if (hasFormula()) if (hasFormula())

View File

@ -1,27 +1,23 @@
/**************************************************************************** //--------------------------------------------------------------------
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> //
** All right reserved. // QXlsx https://github.com/j2doll/QXlsx
** //
** Permission is hereby granted, free of charge, to any person obtaining // GPL License v3 https://www.gnu.org/licenses/gpl-3.0.en.html
** a copy of this software and associated documentation files (the //
** "Software"), to deal in the Software without restriction, including // This program is free software: you can redistribute it and/or modify
** without limitation the rights to use, copy, modify, merge, publish, // it under the terms of the GNU General Public License as published by
** distribute, sublicense, and/or sell copies of the Software, and to // the Free Software Foundation, either version 3 of the License, or
** permit persons to whom the Software is furnished to do so, subject to // (at your option) any later version.
** the following conditions: //
** // This program is distributed in the hope that it will be useful,
** The above copyright notice and this permission notice shall be // but WITHOUT ANY WARRANTY; without even the implied warranty of
** included in all copies or substantial portions of the Software. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** // GNU General Public License for more details.
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, //
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // You should have received a copy of the GNU General Public License
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // along with this program. If not, see <http://www.gnu.org/licenses/>.
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE //--------------------------------------------------------------------
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
****************************************************************************/
#include "xlsxformat.h" #include "xlsxformat.h"
#include "xlsxformat_p.h" #include "xlsxformat_p.h"
#include "xlsxcolor_p.h" #include "xlsxcolor_p.h"
@ -255,11 +251,16 @@ void Format::setNumberFormat(const QString &format)
*/ */
bool Format::isDateTimeFormat() const bool Format::isDateTimeFormat() const
{ {
if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) { //NOTICE:
if (hasProperty(FormatPrivate::P_NumFmt_FormatCode))
{
//Custom numFmt, so //Custom numFmt, so
//Gauss from the number string //Gauss from the number string
return NumFormatParser::isDateTime(numberFormat()); return NumFormatParser::isDateTime(numberFormat());
} else if (hasProperty(FormatPrivate::P_NumFmt_Id)){ }
else if (hasProperty(FormatPrivate::P_NumFmt_Id))
{
//Non-custom numFmt //Non-custom numFmt
int idx = numberFormatIndex(); int idx = numberFormatIndex();

View File

@ -304,6 +304,7 @@ void SharedStrings::readPlainStringPart(QXmlStreamReader &reader, RichString &ri
//QXmlStreamAttributes attributes = reader.attributes(); //QXmlStreamAttributes attributes = reader.attributes();
// NOTICE: CHECK POINT
QString text = reader.readElementText(); QString text = reader.readElementText();
richString.addFragment(text, Format()); richString.addFragment(text, Format());
} }

View File

@ -1901,16 +1901,20 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
Q_Q(Worksheet); Q_Q(Worksheet);
Q_ASSERT(reader.name() == QLatin1String("sheetData")); Q_ASSERT(reader.name() == QLatin1String("sheetData"));
while (!reader.atEnd() && !(reader.name() == QLatin1String("sheetData") && reader.tokenType() == QXmlStreamReader::EndElement)) { while (!reader.atEnd() && !(reader.name() == QLatin1String("sheetData") && reader.tokenType() == QXmlStreamReader::EndElement))
if (reader.readNextStartElement()) { {
if (reader.name() == QLatin1String("row")) { if (reader.readNextStartElement())
{
if (reader.name() == QLatin1String("row"))
{
QXmlStreamAttributes attributes = reader.attributes(); QXmlStreamAttributes attributes = reader.attributes();
if (attributes.hasAttribute(QLatin1String("customFormat")) if (attributes.hasAttribute(QLatin1String("customFormat"))
|| attributes.hasAttribute(QLatin1String("customHeight")) || attributes.hasAttribute(QLatin1String("customHeight"))
|| attributes.hasAttribute(QLatin1String("hidden")) || attributes.hasAttribute(QLatin1String("hidden"))
|| attributes.hasAttribute(QLatin1String("outlineLevel")) || attributes.hasAttribute(QLatin1String("outlineLevel"))
|| attributes.hasAttribute(QLatin1String("collapsed"))) { || attributes.hasAttribute(QLatin1String("collapsed")))
{
QSharedPointer<XlsxRowInfo> info(new XlsxRowInfo); QSharedPointer<XlsxRowInfo> info(new XlsxRowInfo);
if (attributes.hasAttribute(QLatin1String("customFormat")) && attributes.hasAttribute(QLatin1String("s"))) { if (attributes.hasAttribute(QLatin1String("customFormat")) && attributes.hasAttribute(QLatin1String("s"))) {
@ -1943,6 +1947,8 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
} }
else if (reader.name() == QLatin1String("c")) // Cell else if (reader.name() == QLatin1String("c")) // Cell
{ {
//Cell //Cell
QXmlStreamAttributes attributes = reader.attributes(); QXmlStreamAttributes attributes = reader.attributes();
QString r = attributes.value(QLatin1String("r")).toString(); QString r = attributes.value(QLatin1String("r")).toString();
@ -1951,12 +1957,17 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
//get format //get format
Format format; Format format;
int styleIndex = -1; int styleIndex = -1;
if (attributes.hasAttribute(QLatin1String("s"))) // Style if (attributes.hasAttribute(QLatin1String("s"))) // a Style defined in the styles.xml file.
{ {
//"s" == style index //"s" == style index
int idx = attributes.value(QLatin1String("s")).toString().toInt(); int idx = attributes.value(QLatin1String("s")).toString().toInt();
styleIndex = idx;
format = workbook->styles()->xfFormat(idx); format = workbook->styles()->xfFormat(idx);
styleIndex = idx;
// NOTICE: cell style
/*
*/
////Empty format exists in styles xf table of real .xlsx files, see issue #65. ////Empty format exists in styles xf table of real .xlsx files, see issue #65.
//if (!format.isValid()) //if (!format.isValid())
@ -1971,12 +1982,17 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
{ {
cellType = Cell::SharedStringType; cellType = Cell::SharedStringType;
// NOTICE:
// QUESTION; if cell type is 's'tring type. Then, Is the cell always string type?
/*
// TESTING:
// NOTICE: somtimes 's' is not string type. it may be date-time type. // NOTICE: somtimes 's' is not string type. it may be date-time type.
if ( styleIndex == 10 || if ( styleIndex == 10 ||
styleIndex == 12 ) styleIndex == 12 )
{ {
cellType = Cell::NumberType; cellType = Cell::NumberType;
} }
*/
} }
else if (typeString == QLatin1String("inlineStr")) else if (typeString == QLatin1String("inlineStr"))
cellType = Cell::InlineStringType; cellType = Cell::InlineStringType;
@ -1992,27 +2008,42 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
QSharedPointer<Cell> cell(new Cell(QVariant() ,cellType, format, q)); QSharedPointer<Cell> cell(new Cell(QVariant() ,cellType, format, q));
while (!reader.atEnd() && !(reader.name() == QLatin1String("c") && reader.tokenType() == QXmlStreamReader::EndElement)) { while (!reader.atEnd() && !(reader.name() == QLatin1String("c") && reader.tokenType() == QXmlStreamReader::EndElement)) {
if (reader.readNextStartElement()) { if (reader.readNextStartElement())
if (reader.name() == QLatin1String("f")) { {
if (reader.name() == QLatin1String("f"))
{
CellFormula &formula = cell->d_func()->formula; CellFormula &formula = cell->d_func()->formula;
formula.loadFromXml(reader); formula.loadFromXml(reader);
if (formula.formulaType() == CellFormula::SharedType && !formula.formulaText().isEmpty()) { if (formula.formulaType() == CellFormula::SharedType && !formula.formulaText().isEmpty())
{
sharedFormulaMap[formula.sharedIndex()] = formula; sharedFormulaMap[formula.sharedIndex()] = formula;
} }
} else if (reader.name() == QLatin1String("v")) { }
else if (reader.name() == QLatin1String("v")) // Value
{
// NOTICE: CHECK POINT
QString value = reader.readElementText(); QString value = reader.readElementText();
if (cellType == Cell::SharedStringType) { if (cellType == Cell::SharedStringType)
{
int sst_idx = value.toInt(); int sst_idx = value.toInt();
sharedStrings()->incRefByStringIndex(sst_idx); sharedStrings()->incRefByStringIndex(sst_idx);
RichString rs = sharedStrings()->getSharedString(sst_idx); RichString rs = sharedStrings()->getSharedString(sst_idx);
cell->d_func()->value = rs.toPlainString(); QString strPlainString = rs.toPlainString();
cell->d_func()->value = strPlainString;
if (rs.isRichString()) if (rs.isRichString())
cell->d_func()->richString = rs; cell->d_func()->richString = rs;
} else if (cellType == Cell::NumberType) { }
else if (cellType == Cell::NumberType)
{
cell->d_func()->value = value.toDouble(); cell->d_func()->value = value.toDouble();
} else if (cellType == Cell::BooleanType) { }
else if (cellType == Cell::BooleanType)
{
cell->d_func()->value = value.toInt() ? true : false; cell->d_func()->value = value.toInt() ? true : false;
} else { //Cell::ErrorType and Cell::StringType }
else
{ //Cell::ErrorType and Cell::StringType
cell->d_func()->value = value; cell->d_func()->value = value;
} }
} else if (reader.name() == QLatin1String("is")) { } else if (reader.name() == QLatin1String("is")) {