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:
parent
b259f95120
commit
acc9e99bbc
@ -131,13 +131,15 @@ QVariant Cell::readValue() const
|
||||
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
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret; // or. ...?
|
||||
}
|
||||
|
||||
if (hasFormula())
|
||||
|
@ -1,27 +1,23 @@
|
||||
/****************************************************************************
|
||||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
|
||||
** All right reserved.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining
|
||||
** a copy of this software and associated documentation files (the
|
||||
** "Software"), to deal in the Software without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Software, and to
|
||||
** permit persons to whom the Software is furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be
|
||||
** included in all copies or substantial portions of the Software.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
// QXlsx https://github.com/j2doll/QXlsx
|
||||
//
|
||||
// GPL License v3 https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
#include "xlsxformat.h"
|
||||
#include "xlsxformat_p.h"
|
||||
#include "xlsxcolor_p.h"
|
||||
@ -255,11 +251,16 @@ void Format::setNumberFormat(const QString &format)
|
||||
*/
|
||||
bool Format::isDateTimeFormat() const
|
||||
{
|
||||
if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) {
|
||||
//NOTICE:
|
||||
|
||||
if (hasProperty(FormatPrivate::P_NumFmt_FormatCode))
|
||||
{
|
||||
//Custom numFmt, so
|
||||
//Gauss from the number string
|
||||
return NumFormatParser::isDateTime(numberFormat());
|
||||
} else if (hasProperty(FormatPrivate::P_NumFmt_Id)){
|
||||
}
|
||||
else if (hasProperty(FormatPrivate::P_NumFmt_Id))
|
||||
{
|
||||
//Non-custom numFmt
|
||||
int idx = numberFormatIndex();
|
||||
|
||||
|
@ -304,6 +304,7 @@ void SharedStrings::readPlainStringPart(QXmlStreamReader &reader, RichString &ri
|
||||
|
||||
//QXmlStreamAttributes attributes = reader.attributes();
|
||||
|
||||
// NOTICE: CHECK POINT
|
||||
QString text = reader.readElementText();
|
||||
richString.addFragment(text, Format());
|
||||
}
|
||||
|
@ -1901,16 +1901,20 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
|
||||
Q_Q(Worksheet);
|
||||
Q_ASSERT(reader.name() == QLatin1String("sheetData"));
|
||||
|
||||
while (!reader.atEnd() && !(reader.name() == QLatin1String("sheetData") && reader.tokenType() == QXmlStreamReader::EndElement)) {
|
||||
if (reader.readNextStartElement()) {
|
||||
if (reader.name() == QLatin1String("row")) {
|
||||
while (!reader.atEnd() && !(reader.name() == QLatin1String("sheetData") && reader.tokenType() == QXmlStreamReader::EndElement))
|
||||
{
|
||||
if (reader.readNextStartElement())
|
||||
{
|
||||
if (reader.name() == QLatin1String("row"))
|
||||
{
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
|
||||
if (attributes.hasAttribute(QLatin1String("customFormat"))
|
||||
|| attributes.hasAttribute(QLatin1String("customHeight"))
|
||||
|| attributes.hasAttribute(QLatin1String("hidden"))
|
||||
|| attributes.hasAttribute(QLatin1String("outlineLevel"))
|
||||
|| attributes.hasAttribute(QLatin1String("collapsed"))) {
|
||||
|| attributes.hasAttribute(QLatin1String("collapsed")))
|
||||
{
|
||||
|
||||
QSharedPointer<XlsxRowInfo> info(new XlsxRowInfo);
|
||||
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
|
||||
{
|
||||
|
||||
|
||||
//Cell
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
QString r = attributes.value(QLatin1String("r")).toString();
|
||||
@ -1951,12 +1957,17 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
|
||||
//get format
|
||||
Format format;
|
||||
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
|
||||
int idx = attributes.value(QLatin1String("s")).toString().toInt();
|
||||
styleIndex = 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.
|
||||
//if (!format.isValid())
|
||||
@ -1971,12 +1982,17 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
|
||||
{
|
||||
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.
|
||||
if ( styleIndex == 10 ||
|
||||
styleIndex == 12 )
|
||||
{
|
||||
cellType = Cell::NumberType;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else if (typeString == QLatin1String("inlineStr"))
|
||||
cellType = Cell::InlineStringType;
|
||||
@ -1992,27 +2008,42 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
|
||||
|
||||
QSharedPointer<Cell> cell(new Cell(QVariant() ,cellType, format, q));
|
||||
while (!reader.atEnd() && !(reader.name() == QLatin1String("c") && reader.tokenType() == QXmlStreamReader::EndElement)) {
|
||||
if (reader.readNextStartElement()) {
|
||||
if (reader.name() == QLatin1String("f")) {
|
||||
if (reader.readNextStartElement())
|
||||
{
|
||||
if (reader.name() == QLatin1String("f"))
|
||||
{
|
||||
CellFormula &formula = cell->d_func()->formula;
|
||||
formula.loadFromXml(reader);
|
||||
if (formula.formulaType() == CellFormula::SharedType && !formula.formulaText().isEmpty()) {
|
||||
if (formula.formulaType() == CellFormula::SharedType && !formula.formulaText().isEmpty())
|
||||
{
|
||||
sharedFormulaMap[formula.sharedIndex()] = formula;
|
||||
}
|
||||
} else if (reader.name() == QLatin1String("v")) {
|
||||
}
|
||||
else if (reader.name() == QLatin1String("v")) // Value
|
||||
{
|
||||
// NOTICE: CHECK POINT
|
||||
|
||||
QString value = reader.readElementText();
|
||||
if (cellType == Cell::SharedStringType) {
|
||||
if (cellType == Cell::SharedStringType)
|
||||
{
|
||||
int sst_idx = value.toInt();
|
||||
sharedStrings()->incRefByStringIndex(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())
|
||||
cell->d_func()->richString = rs;
|
||||
} else if (cellType == Cell::NumberType) {
|
||||
}
|
||||
else if (cellType == Cell::NumberType)
|
||||
{
|
||||
cell->d_func()->value = value.toDouble();
|
||||
} else if (cellType == Cell::BooleanType) {
|
||||
}
|
||||
else if (cellType == Cell::BooleanType)
|
||||
{
|
||||
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;
|
||||
}
|
||||
} else if (reader.name() == QLatin1String("is")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user