Skip to content

Commit 0461eac

Browse files
committed
issue#173
1 parent 8817bb9 commit 0461eac

File tree

2 files changed

+72
-21
lines changed

2 files changed

+72
-21
lines changed

QXlsx/source/xlsxcolor.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,53 @@ XlsxColor::operator QVariant() const
119119

120120
QColor XlsxColor::fromARGBString(const QString &c)
121121
{
122-
Q_ASSERT(c.length() == 8);
122+
// issue #173 https://github.com/QtExcel/QXlsx/issues/173
123+
123124
QColor color;
125+
QString strColor = "00000000";
126+
127+
if ( c.length() == 8 )
128+
{
129+
strColor = c;
130+
}
131+
132+
if ( c.length() == 6 )
133+
{
134+
strColor = QString("00") + c;
135+
}
124136

125137
#if QT_VERSION >= 0x060000 // Qt 6.0 or over
126-
color.setAlpha(c.mid(0, 2).toInt(0, 16));
127-
color.setRed(c.mid(2, 2).toInt(0, 16));
128-
color.setGreen(c.mid(4, 2).toInt(0, 16));
129-
color.setBlue(c.mid(6, 2).toInt(0, 16));
138+
QString strAlpha = strColor.mid(0, 2);
139+
int alpha = strAlpha.toInt(0, 16);
140+
color.setAlpha( alpha );
141+
142+
QString strRed = strColor.mid(2, 2);
143+
int red = strRed.toInt(0, 16);
144+
color.setRed( red );
145+
146+
QString strGreen = strColor.mid(4, 2);
147+
int green = strGreen.toInt(0, 16);
148+
color.setGreen( green );
149+
150+
QString strBlue = strColor.mid(6, 2);
151+
int blue = strBlue.toInt(0, 16);
152+
color.setBlue( blue );
130153
#else
131-
color.setAlpha(c.midRef(0, 2).toInt(0, 16));
132-
color.setRed(c.midRef(2, 2).toInt(0, 16));
133-
color.setGreen(c.midRef(4, 2).toInt(0, 16));
134-
color.setBlue(c.midRef(6, 2).toInt(0, 16));
154+
QStringRef strAlpha = strColor.midRef(0, 2);
155+
int alpha = strAlpha.toInt(0, 16);
156+
color.setAlpha( alpha );
157+
158+
QStringRef strRed = strColor.midRef(2, 2);
159+
int red = strRed.toInt(0, 16);
160+
color.setRed( red );
161+
162+
QStringRef strGreen = strColor.midRef(4, 2);
163+
int green = strGreen.toInt(0, 16);
164+
color.setGreen( green );
165+
166+
QStringRef strBlue = strColor.midRef(6, 2);
167+
int blue = strBlue.toInt(0, 16);
168+
color.setBlue( blue );
135169
#endif
136170

137171
return color;

QXlsx/source/xlsxworksheet.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,31 +2616,48 @@ void WorksheetPrivate::loadXmlColumnsInfo(QXmlStreamReader &reader)
26162616

26172617
void WorksheetPrivate::loadXmlMergeCells(QXmlStreamReader &reader)
26182618
{
2619-
Q_ASSERT(reader.name() == QLatin1String("mergeCells"));
2619+
// issue #173 https://github.com/QtExcel/QXlsx/issues/173
26202620

2621-
QXmlStreamAttributes attributes = reader.attributes();
2622-
int count = attributes.value(QLatin1String("count")).toString().toInt();
2621+
Q_ASSERT(reader.name() == QLatin1String("mergeCells"));
2622+
2623+
QXmlStreamAttributes attributes = reader.attributes();
2624+
2625+
bool isCount = attributes.hasAttribute(QLatin1String("count"));
2626+
int count = 0;
2627+
if ( !isCount )
2628+
{
2629+
qWarning("no count");
2630+
}
2631+
else
2632+
{
2633+
count = attributes.value(QLatin1String("count")).toString().toInt();
2634+
}
26232635

26242636
while ( !reader.atEnd() &&
26252637
!(reader.name() == QLatin1String("mergeCells") &&
26262638
reader.tokenType() == QXmlStreamReader::EndElement) )
26272639
{
2628-
reader.readNextStartElement();
2640+
reader.readNextStartElement();
26292641
if (reader.tokenType() == QXmlStreamReader::StartElement)
26302642
{
26312643
if (reader.name() == QLatin1String("mergeCell"))
26322644
{
2633-
QXmlStreamAttributes attrs = reader.attributes();
2634-
QString rangeStr = attrs.value(QLatin1String("ref")).toString();
2635-
merges.append(CellRange(rangeStr));
2636-
}
2637-
}
2638-
}
2645+
QXmlStreamAttributes attrs = reader.attributes();
2646+
QString rangeStr = attrs.value(QLatin1String("ref")).toString();
2647+
merges.append(CellRange(rangeStr));
2648+
}
2649+
}
2650+
}
26392651

2640-
if (merges.size() != count)
2652+
if (isCount)
26412653
{
2642-
qWarning("read merge cells error");
2654+
int mergesSize = merges.size();
2655+
if ( mergesSize != count )
2656+
{
2657+
qWarning("read merge cells error");
2658+
}
26432659
}
2660+
26442661
}
26452662

26462663
void WorksheetPrivate::loadXmlDataValidations(QXmlStreamReader &reader)

0 commit comments

Comments
 (0)