diff --git a/src/xlsx/xlsxcolor.cpp b/src/xlsx/xlsxcolor.cpp index 7aec0bc..2ec6439 100644 --- a/src/xlsx/xlsxcolor.cpp +++ b/src/xlsx/xlsxcolor.cpp @@ -77,7 +77,7 @@ bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const writer.writeEmptyElement(QStringLiteral("color")); if (val.userType() == qMetaTypeId()) { - writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+val.value().name().mid(1));//remove # + writer.writeAttribute(QStringLiteral("rgb"), XlsxColor::toARGBString(val.value())); } else if (val.userType() == QMetaType::QStringList) { QStringList themes = val.toStringList(); writer.writeAttribute(QStringLiteral("theme"), themes[0]); @@ -155,6 +155,24 @@ QDataStream &operator>>(QDataStream &s, XlsxColor &color) return s; } +QColor XlsxColor::fromARGBString(const QString &c) +{ + Q_ASSERT(c.length() == 8); + QColor color; + color.setAlpha(c.mid(0, 2).toInt(0, 16)); + color.setRed(c.mid(2, 2).toInt(0, 16)); + color.setGreen(c.mid(4, 2).toInt(0, 16)); + color.setBlue(c.mid(6, 2).toInt(0, 16)); + return color; +} + +QString XlsxColor::toARGBString(const QColor &c) +{ + QString color; + color.sprintf("%02X%02X%02X%02X", c.alpha(), c.red(), c.green(), c.blue()); + return color; +} + #endif } // namespace QXlsx diff --git a/src/xlsx/xlsxcolor_p.h b/src/xlsx/xlsxcolor_p.h index a34ff22..a4081ae 100644 --- a/src/xlsx/xlsxcolor_p.h +++ b/src/xlsx/xlsxcolor_p.h @@ -66,6 +66,9 @@ public: operator QVariant() const; + static QColor fromARGBString(const QString &c); + static QString toARGBString(const QColor &c); + bool saveToXml(QXmlStreamWriter &writer, const QString &node=QString()) const; bool loadFromXml(QXmlStreamReader &reader); diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index a597a58..836d0c1 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/src/xlsx/xlsxstyles.cpp @@ -1222,7 +1222,7 @@ bool Styles::readIndexedColors(QXmlStreamReader &reader) if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("rgbColor")) { QString color = reader.attributes().value(QLatin1String("rgb")).toString(); - m_indexedColors.append(fromARGBString(color)); + m_indexedColors.append(XlsxColor::fromARGBString(color)); } } } diff --git a/src/xlsx/xlsxutility.cpp b/src/xlsx/xlsxutility.cpp index 0e6eeb2..5026739 100755 --- a/src/xlsx/xlsxutility.cpp +++ b/src/xlsx/xlsxutility.cpp @@ -54,16 +54,6 @@ QStringList splitPath(const QString &path) return QStringList()<")); + QVERIFY(xmlData.contains("")); } void StylesTest::testWriteBorders() diff --git a/tests/auto/xlsxconditionalformatting/tst_conditionalformattingtest.cpp b/tests/auto/xlsxconditionalformatting/tst_conditionalformattingtest.cpp index 21fde11..8b8e0e5 100644 --- a/tests/auto/xlsxconditionalformatting/tst_conditionalformattingtest.cpp +++ b/tests/auto/xlsxconditionalformatting/tst_conditionalformattingtest.cpp @@ -93,7 +93,7 @@ void ConditionalFormattingTest::testDataBarRules() QByteArray res = "" "" "" - "" + "" ""; QVERIFY(buffer.buffer().contains(res)); }