diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index 40e3981..7542ce2 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/src/xlsx/xlsxstyles.cpp @@ -467,22 +467,17 @@ void Styles::writeFill(QXmlStreamWriter &writer, const Format &fill, bool /*isDx writer.writeStartElement(QStringLiteral("patternFill")); writer.writeAttribute(QStringLiteral("patternType"), patternStrings[fill.fillPattern()]); // For a solid fill, Excel reverses the role of foreground and background colours - if (fill.hasProperty(FormatPrivate::P_Fill_FgColor)) { - XlsxColor color = fill.property(FormatPrivate::P_Fill_FgColor).value(); - if (fill.fillPattern() == Format::PatternSolid) - color.saveToXml(writer, QStringLiteral("bgColor")); - else - color.saveToXml(writer, QStringLiteral("fgColor")); - } - - if (fill.hasProperty(FormatPrivate::P_Fill_BgColor)) { - XlsxColor color = fill.property(FormatPrivate::P_Fill_BgColor).value(); - if (fill.fillPattern() == Format::PatternSolid) - color.saveToXml(writer, QStringLiteral("fgColor")); - else - color.saveToXml(writer, QStringLiteral("bgColor")); + if (fill.fillPattern() == Format::PatternSolid) { + if (fill.hasProperty(FormatPrivate::P_Fill_BgColor)) + fill.property(FormatPrivate::P_Fill_BgColor).value().saveToXml(writer, QStringLiteral("fgColor")); + if (fill.hasProperty(FormatPrivate::P_Fill_FgColor)) + fill.property(FormatPrivate::P_Fill_FgColor).value().saveToXml(writer, QStringLiteral("bgColor")); + } else { + if (fill.hasProperty(FormatPrivate::P_Fill_FgColor)) + fill.property(FormatPrivate::P_Fill_FgColor).value().saveToXml(writer, QStringLiteral("fgColor")); + if (fill.hasProperty(FormatPrivate::P_Fill_BgColor)) + fill.property(FormatPrivate::P_Fill_BgColor).value().saveToXml(writer, QStringLiteral("bgColor")); } - writer.writeEndElement();//patternFill writer.writeEndElement();//fill }