Bugfix: properly parse fillpattern colors and implement optional boolean fields.
Conflicts: src/xlsx/xlsxutility.cpp src/xlsx/xlsxutility_p.h
This commit is contained in:
+58
-36
@@ -886,21 +886,29 @@ bool Styles::readFill(QXmlStreamReader &reader, Format &fill)
|
|||||||
if (attributes.hasAttribute(QLatin1String("patternType"))) {
|
if (attributes.hasAttribute(QLatin1String("patternType"))) {
|
||||||
QString pattern = attributes.value(QLatin1String("patternType")).toString();
|
QString pattern = attributes.value(QLatin1String("patternType")).toString();
|
||||||
fill.setFillPattern(patternValues.contains(pattern) ? patternValues[pattern] : Format::PatternNone);
|
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"));
|
bool hasCount = attributes.hasAttribute(QLatin1String("count"));
|
||||||
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
||||||
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
||||||
&& reader.name() == QLatin1String("cellXfs"))) {
|
&& reader.name() == QLatin1String("cellXfs"))) {
|
||||||
reader.readNextStartElement();
|
reader.readNextStartElement();
|
||||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||||
if (reader.name() == QLatin1String("xf")) {
|
if (reader.name() == QLatin1String("xf")) {
|
||||||
@@ -1054,54 +1062,67 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
|
|||||||
// for (int i=0; i<xfAttrs.size(); ++i)
|
// for (int i=0; i<xfAttrs.size(); ++i)
|
||||||
// qDebug()<<"... "<<i<<" "<<xfAttrs[i].name()<<xfAttrs[i].value();
|
// qDebug()<<"... "<<i<<" "<<xfAttrs[i].name()<<xfAttrs[i].value();
|
||||||
|
|
||||||
if (xfAttrs.hasAttribute(QLatin1String("applyNumberFormat"))) {
|
if (xfAttrs.hasAttribute(QLatin1String("numFmtId"))) {
|
||||||
int numFmtIndex = xfAttrs.value(QLatin1String("numFmtId")).toString().toInt();
|
int numFmtIndex = xfAttrs.value(QLatin1String("numFmtId")).toString().toInt();
|
||||||
if (!m_customNumFmtIdMap.contains(numFmtIndex))
|
bool apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyNumberFormat")).toString());
|
||||||
format.setNumberFormatIndex(numFmtIndex);
|
if(apply) {
|
||||||
else
|
if (!m_customNumFmtIdMap.contains(numFmtIndex))
|
||||||
format.setNumberFormat(numFmtIndex, m_customNumFmtIdMap[numFmtIndex]->formatString);
|
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();
|
int fontIndex = xfAttrs.value(QLatin1String("fontId")).toString().toInt();
|
||||||
if (fontIndex >= m_fontsList.size()) {
|
if (fontIndex >= m_fontsList.size()) {
|
||||||
qDebug("Error read styles.xml, cellXfs fontId");
|
qDebug("Error read styles.xml, cellXfs fontId");
|
||||||
} else {
|
} else {
|
||||||
Format fontFormat = m_fontsList[fontIndex];
|
bool apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyFont")).toString());
|
||||||
for (int i=FormatPrivate::P_Font_STARTID; i<FormatPrivate::P_Font_ENDID; ++i) {
|
if(apply) {
|
||||||
if (fontFormat.hasProperty(i))
|
Format fontFormat = m_fontsList[fontIndex];
|
||||||
format.setProperty(i, fontFormat.property(i));
|
for (int i=FormatPrivate::P_Font_STARTID; i<FormatPrivate::P_Font_ENDID; ++i) {
|
||||||
|
if (fontFormat.hasProperty(i))
|
||||||
|
format.setProperty(i, fontFormat.property(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xfAttrs.hasAttribute(QLatin1String("applyFill"))) {
|
if (xfAttrs.hasAttribute(QLatin1String("fillId"))) {
|
||||||
int id = xfAttrs.value(QLatin1String("fillId")).toString().toInt();
|
int id = xfAttrs.value(QLatin1String("fillId")).toString().toInt();
|
||||||
if (id >= m_fillsList.size()) {
|
if (id >= m_fillsList.size()) {
|
||||||
qDebug("Error read styles.xml, cellXfs fillId");
|
qDebug("Error read styles.xml, cellXfs fillId");
|
||||||
} else {
|
} else {
|
||||||
Format fillFormat = m_fillsList[id];
|
bool apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyFill")).toString());
|
||||||
for (int i=FormatPrivate::P_Fill_STARTID; i<FormatPrivate::P_Fill_ENDID; ++i) {
|
if(apply) {
|
||||||
if (fillFormat.hasProperty(i))
|
Format fillFormat = m_fillsList[id];
|
||||||
format.setProperty(i, fillFormat.property(i));
|
for (int i=FormatPrivate::P_Fill_STARTID; i<FormatPrivate::P_Fill_ENDID; ++i) {
|
||||||
|
if (fillFormat.hasProperty(i))
|
||||||
|
format.setProperty(i, fillFormat.property(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xfAttrs.hasAttribute(QLatin1String("applyBorder"))) {
|
if (xfAttrs.hasAttribute(QLatin1String("borderId"))) {
|
||||||
int id = xfAttrs.value(QLatin1String("borderId")).toString().toInt();
|
int id = xfAttrs.value(QLatin1String("borderId")).toString().toInt();
|
||||||
if (id >= m_bordersList.size()) {
|
if (id >= m_bordersList.size()) {
|
||||||
qDebug("Error read styles.xml, cellXfs borderId");
|
qDebug("Error read styles.xml, cellXfs borderId");
|
||||||
} else {
|
} else {
|
||||||
Format borderFormat = m_bordersList[id];
|
bool apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyBorder")).toString());
|
||||||
for (int i=FormatPrivate::P_Border_STARTID; i<FormatPrivate::P_Border_ENDID; ++i) {
|
if(apply) {
|
||||||
if (borderFormat.hasProperty(i))
|
Format borderFormat = m_bordersList[id];
|
||||||
format.setProperty(i, borderFormat.property(i));
|
for (int i=FormatPrivate::P_Border_STARTID; i<FormatPrivate::P_Border_ENDID; ++i) {
|
||||||
|
if (borderFormat.hasProperty(i))
|
||||||
|
format.setProperty(i, borderFormat.property(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xfAttrs.hasAttribute(QLatin1String("applyAlignment"))) {
|
bool apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyAlignment")).toString());
|
||||||
|
if(apply) {
|
||||||
reader.readNextStartElement();
|
reader.readNextStartElement();
|
||||||
if (reader.name() == QLatin1String("alignment")) {
|
if (reader.name() == QLatin1String("alignment")) {
|
||||||
QXmlStreamAttributes alignAttrs = reader.attributes();
|
QXmlStreamAttributes alignAttrs = reader.attributes();
|
||||||
@@ -1149,6 +1170,7 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
|
|||||||
|
|
||||||
if (alignAttrs.hasAttribute(QLatin1String("shrinkToFit")))
|
if (alignAttrs.hasAttribute(QLatin1String("shrinkToFit")))
|
||||||
format.setShrinkToFit(true);
|
format.setShrinkToFit(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,15 @@
|
|||||||
|
|
||||||
namespace QXlsx {
|
namespace QXlsx {
|
||||||
|
|
||||||
|
bool parseXsdBoolean(const QString &value, bool defaultValue)
|
||||||
|
{
|
||||||
|
if (value == QLatin1String("1") || value == QLatin1String("true"))
|
||||||
|
return true;
|
||||||
|
if (value == QLatin1String("0") || value == QLatin1String("false"))
|
||||||
|
return false;
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList splitPath(const QString &path)
|
QStringList splitPath(const QString &path)
|
||||||
{
|
{
|
||||||
int idx = path.lastIndexOf(QLatin1Char('/'));
|
int idx = path.lastIndexOf(QLatin1Char('/'));
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class QTime;
|
|||||||
|
|
||||||
namespace QXlsx {
|
namespace QXlsx {
|
||||||
|
|
||||||
|
XLSX_AUTOTEST_EXPORT bool parseXsdBoolean(const QString &value, bool defaultValue=false);
|
||||||
|
|
||||||
XLSX_AUTOTEST_EXPORT QStringList splitPath(const QString &path);
|
XLSX_AUTOTEST_EXPORT QStringList splitPath(const QString &path);
|
||||||
XLSX_AUTOTEST_EXPORT QString getRelFilePath(const QString &filePath);
|
XLSX_AUTOTEST_EXPORT QString getRelFilePath(const QString &filePath);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user