Skip to content

Commit

Permalink
issue#173
Browse files Browse the repository at this point in the history
  • Loading branch information
j2doll committed Aug 11, 2021
1 parent 8817bb9 commit 0461eac
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 21 deletions.
52 changes: 43 additions & 9 deletions QXlsx/source/xlsxcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 29 additions & 12 deletions QXlsx/source/xlsxworksheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
QXmlStreamAttributes attrs = reader.attributes();
QString rangeStr = attrs.value(QLatin1String("ref")).toString();
merges.append(CellRange(rangeStr));
}
}
}

if (merges.size() != count)
if (isCount)
{
qWarning("read merge cells error");
int mergesSize = merges.size();
if ( mergesSize != count )
{
qWarning("read merge cells error");
}
}

}

void WorksheetPrivate::loadXmlDataValidations(QXmlStreamReader &reader)
Expand Down

0 comments on commit 0461eac

Please sign in to comment.