From b74e49d097ca8eb29052ef21127fb4e3141c7757 Mon Sep 17 00:00:00 2001 From: eho Date: Wed, 19 Mar 2014 11:36:08 +0100 Subject: [PATCH] Bugfix: properly parse fillpattern colors and implement optional boolean fields. Conflicts: src/xlsx/xlsxutility.cpp src/xlsx/xlsxutility_p.h --- src/xlsx/xlsxstyles.cpp | 94 +++++++++++++++++++++++++--------------- src/xlsx/xlsxutility.cpp | 9 ++++ src/xlsx/xlsxutility_p.h | 2 + 3 files changed, 69 insertions(+), 36 deletions(-) diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index 2c32bfb..59d9adc 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/src/xlsx/xlsxstyles.cpp @@ -886,21 +886,29 @@ bool Styles::readFill(QXmlStreamReader &reader, Format &fill) if (attributes.hasAttribute(QLatin1String("patternType"))) { QString pattern = attributes.value(QLatin1String("patternType")).toString(); fill.setFillPattern(patternValues.contains(pattern) ? patternValues[pattern] : Format::PatternNone); + + //parse foreground and background colors if they exist + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("patternFill"))) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("fgColor")) { + XlsxColor c; + c.loadFromXml(reader); + if (fill.fillPattern() == Format::PatternSolid) + fill.setProperty(FormatPrivate::P_Fill_BgColor, c); + else + fill.setProperty(FormatPrivate::P_Fill_FgColor, c); + } else if (reader.name() == QLatin1String("bgColor")) { + XlsxColor c; + c.loadFromXml(reader); + if (fill.fillPattern() == Format::PatternSolid) + fill.setProperty(FormatPrivate::P_Fill_FgColor, c); + else + fill.setProperty(FormatPrivate::P_Fill_BgColor, c); + } + } + } } - } else if (reader.name() == QLatin1String("fgColor")) { - XlsxColor c; - c.loadFromXml(reader); - if (fill.fillPattern() == Format::PatternSolid) - fill.setProperty(FormatPrivate::P_Fill_BgColor, c); - else - fill.setProperty(FormatPrivate::P_Fill_FgColor, c); - } else if (reader.name() == QLatin1String("bgColor")) { - XlsxColor c; - c.loadFromXml(reader); - if (fill.fillPattern() == Format::PatternSolid) - fill.setProperty(FormatPrivate::P_Fill_FgColor, c); - else - fill.setProperty(FormatPrivate::P_Fill_BgColor, c); } } } @@ -1042,7 +1050,7 @@ bool Styles::readCellXfs(QXmlStreamReader &reader) bool hasCount = attributes.hasAttribute(QLatin1String("count")); int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1; while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("cellXfs"))) { + && reader.name() == QLatin1String("cellXfs"))) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("xf")) { @@ -1054,54 +1062,67 @@ bool Styles::readCellXfs(QXmlStreamReader &reader) // for (int i=0; iformatString); + bool apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyNumberFormat")).toString()); + if(apply) { + if (!m_customNumFmtIdMap.contains(numFmtIndex)) + format.setNumberFormatIndex(numFmtIndex); + else + format.setNumberFormat(numFmtIndex, m_customNumFmtIdMap[numFmtIndex]->formatString); + } } - if (xfAttrs.hasAttribute(QLatin1String("applyFont"))) { + if (xfAttrs.hasAttribute(QLatin1String("fontId"))) { int fontIndex = xfAttrs.value(QLatin1String("fontId")).toString().toInt(); if (fontIndex >= m_fontsList.size()) { qDebug("Error read styles.xml, cellXfs fontId"); } else { - Format fontFormat = m_fontsList[fontIndex]; - for (int i=FormatPrivate::P_Font_STARTID; i= m_fillsList.size()) { qDebug("Error read styles.xml, cellXfs fillId"); } else { - Format fillFormat = m_fillsList[id]; - for (int i=FormatPrivate::P_Fill_STARTID; i= m_bordersList.size()) { qDebug("Error read styles.xml, cellXfs borderId"); } else { - Format borderFormat = m_bordersList[id]; - for (int i=FormatPrivate::P_Border_STARTID; i