From 0461eac843358aec56c648ec929ca20da5822fdc Mon Sep 17 00:00:00 2001 From: Jay Two Date: Wed, 11 Aug 2021 22:12:26 +0900 Subject: [PATCH] issue#173 --- QXlsx/source/xlsxcolor.cpp | 52 ++++++++++++++++++++++++++++------ QXlsx/source/xlsxworksheet.cpp | 45 ++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 23 deletions(-) diff --git a/QXlsx/source/xlsxcolor.cpp b/QXlsx/source/xlsxcolor.cpp index 73f6808..430915d 100644 --- a/QXlsx/source/xlsxcolor.cpp +++ b/QXlsx/source/xlsxcolor.cpp @@ -119,19 +119,53 @@ XlsxColor::operator QVariant() const QColor XlsxColor::fromARGBString(const QString &c) { - Q_ASSERT(c.length() == 8); + // issue #173 https://github.com/QtExcel/QXlsx/issues/173 + QColor color; + QString strColor = "00000000"; + + if ( c.length() == 8 ) + { + strColor = c; + } + + if ( c.length() == 6 ) + { + strColor = QString("00") + c; + } #if QT_VERSION >= 0x060000 // Qt 6.0 or over - 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)); + QString strAlpha = strColor.mid(0, 2); + int alpha = strAlpha.toInt(0, 16); + color.setAlpha( alpha ); + + QString strRed = strColor.mid(2, 2); + int red = strRed.toInt(0, 16); + color.setRed( red ); + + QString strGreen = strColor.mid(4, 2); + int green = strGreen.toInt(0, 16); + color.setGreen( green ); + + QString strBlue = strColor.mid(6, 2); + int blue = strBlue.toInt(0, 16); + color.setBlue( blue ); #else - color.setAlpha(c.midRef(0, 2).toInt(0, 16)); - color.setRed(c.midRef(2, 2).toInt(0, 16)); - color.setGreen(c.midRef(4, 2).toInt(0, 16)); - color.setBlue(c.midRef(6, 2).toInt(0, 16)); + QStringRef strAlpha = strColor.midRef(0, 2); + int alpha = strAlpha.toInt(0, 16); + color.setAlpha( alpha ); + + QStringRef strRed = strColor.midRef(2, 2); + int red = strRed.toInt(0, 16); + color.setRed( red ); + + QStringRef strGreen = strColor.midRef(4, 2); + int green = strGreen.toInt(0, 16); + color.setGreen( green ); + + QStringRef strBlue = strColor.midRef(6, 2); + int blue = strBlue.toInt(0, 16); + color.setBlue( blue ); #endif return color; diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index 84696b1..90fd8f1 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -2616,31 +2616,48 @@ void WorksheetPrivate::loadXmlColumnsInfo(QXmlStreamReader &reader) void WorksheetPrivate::loadXmlMergeCells(QXmlStreamReader &reader) { - Q_ASSERT(reader.name() == QLatin1String("mergeCells")); + // issue #173 https://github.com/QtExcel/QXlsx/issues/173 - QXmlStreamAttributes attributes = reader.attributes(); - int count = attributes.value(QLatin1String("count")).toString().toInt(); + Q_ASSERT(reader.name() == QLatin1String("mergeCells")); + + QXmlStreamAttributes attributes = reader.attributes(); + + bool isCount = attributes.hasAttribute(QLatin1String("count")); + int count = 0; + if ( !isCount ) + { + qWarning("no count"); + } + else + { + count = attributes.value(QLatin1String("count")).toString().toInt(); + } while ( !reader.atEnd() && !(reader.name() == QLatin1String("mergeCells") && reader.tokenType() == QXmlStreamReader::EndElement) ) { - reader.readNextStartElement(); + reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("mergeCell")) { - QXmlStreamAttributes attrs = reader.attributes(); - QString rangeStr = attrs.value(QLatin1String("ref")).toString(); - merges.append(CellRange(rangeStr)); - } - } - } - - if (merges.size() != count) - { - qWarning("read merge cells error"); + QXmlStreamAttributes attrs = reader.attributes(); + QString rangeStr = attrs.value(QLatin1String("ref")).toString(); + merges.append(CellRange(rangeStr)); + } + } } + + if (isCount) + { + int mergesSize = merges.size(); + if ( mergesSize != count ) + { + qWarning("read merge cells error"); + } + } + } void WorksheetPrivate::loadXmlDataValidations(QXmlStreamReader &reader)