Don't depend on the "count" attribute
"count" is an optional attribute
This commit is contained in:
+87
-32
@@ -708,11 +708,15 @@ bool Styles::readNumFmts(XmlStreamReader &reader)
|
||||
{
|
||||
Q_ASSERT(reader.name() == QLatin1String("numFmts"));
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
int count = attributes.value(QLatin1String("count")).toString().toInt();
|
||||
for (int i=0; i<count; ++i) {
|
||||
bool hasCount = attributes.hasAttribute(QLatin1String("count"));
|
||||
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
||||
|
||||
//Read utill we find the numFmts end tag or ....
|
||||
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
||||
&& reader.name() == QLatin1String("numFmts"))) {
|
||||
reader.readNextStartElement();
|
||||
if (reader.name() != QLatin1String("numFmt"))
|
||||
return false;
|
||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("numFmt")) {
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
QSharedPointer<XlsxFormatNumberData> fmt (new XlsxFormatNumberData);
|
||||
fmt->formatIndex = attributes.value(QLatin1String("numFmtId")).toString().toInt();
|
||||
@@ -721,22 +725,30 @@ bool Styles::readNumFmts(XmlStreamReader &reader)
|
||||
m_nextCustomNumFmtId = fmt->formatIndex + 1;
|
||||
m_customNumFmtIdMap.insert(fmt->formatIndex, fmt);
|
||||
m_customNumFmtsHash.insert(fmt->formatString, fmt);
|
||||
|
||||
while (!(reader.name() == QLatin1String("numFmt") && reader.tokenType() == QXmlStreamReader::EndElement))
|
||||
reader.readNextStartElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.hasError())
|
||||
qWarning()<<reader.errorString();
|
||||
|
||||
if (hasCount && (count != m_customNumFmtIdMap.size()))
|
||||
qWarning("error read custom numFmts");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Styles::readFonts(XmlStreamReader &reader)
|
||||
{
|
||||
Q_ASSERT(reader.name() == QLatin1String("fonts"));
|
||||
QXmlStreamAttributes attrs = reader.attributes();
|
||||
int count = attrs.value(QLatin1String("count")).toString().toInt();
|
||||
for (int i=0; i<count; ++i) {
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
bool hasCount = attributes.hasAttribute(QLatin1String("count"));
|
||||
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
||||
while(!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
||||
&& reader.name() == QLatin1String("fonts"))) {
|
||||
reader.readNextStartElement();
|
||||
if (reader.name() != QLatin1String("font"))
|
||||
return false;
|
||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("font")) {
|
||||
Format format;
|
||||
readFont(reader, format);
|
||||
m_fontsList.append(format);
|
||||
@@ -744,6 +756,13 @@ bool Styles::readFonts(XmlStreamReader &reader)
|
||||
if (format.isValid())
|
||||
format.setFontIndex(m_fontsList.size()-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reader.hasError())
|
||||
qWarning()<<reader.errorString();
|
||||
|
||||
if (hasCount && (count != m_fontsList.size()))
|
||||
qWarning("error read fonts");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -820,11 +839,13 @@ bool Styles::readFills(XmlStreamReader &reader)
|
||||
Q_ASSERT(reader.name() == QLatin1String("fills"));
|
||||
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
int count = attributes.value(QLatin1String("count")).toString().toInt();
|
||||
for (int i=0; i<count; ++i) {
|
||||
bool hasCount = attributes.hasAttribute(QLatin1String("count"));
|
||||
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
||||
while(!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
||||
&& reader.name() == QLatin1String("fills"))) {
|
||||
reader.readNextStartElement();
|
||||
if (reader.name() != QLatin1String("fill") || reader.tokenType() != QXmlStreamReader::StartElement)
|
||||
return false;
|
||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("fill")) {
|
||||
Format fill;
|
||||
readFill(reader, fill);
|
||||
m_fillsList.append(fill);
|
||||
@@ -832,6 +853,13 @@ bool Styles::readFills(XmlStreamReader &reader)
|
||||
if (fill.isValid())
|
||||
fill.setFillIndex(m_fillsList.size()-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reader.hasError())
|
||||
qWarning()<<reader.errorString();
|
||||
|
||||
if (hasCount && (count != m_fillsList.size()))
|
||||
qWarning("error read fills");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -917,11 +945,13 @@ bool Styles::readBorders(XmlStreamReader &reader)
|
||||
Q_ASSERT(reader.name() == QLatin1String("borders"));
|
||||
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
int count = attributes.value(QLatin1String("count")).toString().toInt();
|
||||
for (int i=0; i<count; ++i) {
|
||||
bool hasCount = attributes.hasAttribute(QLatin1String("count"));
|
||||
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
||||
while(!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
||||
&& reader.name() == QLatin1String("borders"))) {
|
||||
reader.readNextStartElement();
|
||||
if (reader.name() != QLatin1String("border") || reader.tokenType() != QXmlStreamReader::StartElement)
|
||||
return false;
|
||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("border")) {
|
||||
Format border;
|
||||
readBorder(reader, border);
|
||||
m_bordersList.append(border);
|
||||
@@ -929,6 +959,15 @@ bool Styles::readBorders(XmlStreamReader &reader)
|
||||
if (border.isValid())
|
||||
border.setBorderIndex(m_bordersList.size()-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.hasError())
|
||||
qWarning()<<reader.errorString();
|
||||
|
||||
if (hasCount && (count != m_bordersList.size()))
|
||||
qWarning("error read borders");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1057,11 +1096,14 @@ bool Styles::readCellXfs(XmlStreamReader &reader)
|
||||
{
|
||||
Q_ASSERT(reader.name() == QLatin1String("cellXfs"));
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
int count = attributes.value(QLatin1String("count")).toString().toInt();
|
||||
for (int i=0; i<count; ++i) {
|
||||
bool hasCount = attributes.hasAttribute(QLatin1String("count"));
|
||||
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
||||
while(!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
||||
&& reader.name() == QLatin1String("cellXfs"))) {
|
||||
reader.readNextStartElement();
|
||||
if (reader.name() != QLatin1String("xf"))
|
||||
return false;
|
||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("xf")) {
|
||||
|
||||
Format format;
|
||||
QXmlStreamAttributes xfAttrs = reader.attributes();
|
||||
|
||||
@@ -1168,11 +1210,15 @@ bool Styles::readCellXfs(XmlStreamReader &reader)
|
||||
}
|
||||
|
||||
addXfFormat(format, true);
|
||||
|
||||
//Find the endElement of xf
|
||||
while (!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("xf")))
|
||||
reader.readNextStartElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.hasError())
|
||||
qWarning()<<reader.errorString();
|
||||
|
||||
if (hasCount && (count != m_xf_formatsList.size()))
|
||||
qWarning("error read CellXfs");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1181,13 +1227,22 @@ bool Styles::readDxfs(XmlStreamReader &reader)
|
||||
{
|
||||
Q_ASSERT(reader.name() == QLatin1String("dxfs"));
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
int count = attributes.value(QLatin1String("count")).toString().toInt();
|
||||
for (int i=0; i<count; ++i) {
|
||||
bool hasCount = attributes.hasAttribute(QLatin1String("count"));
|
||||
int count = hasCount ? attributes.value(QLatin1String("count")).toString().toInt() : -1;
|
||||
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
|
||||
&& reader.name() == QLatin1String("dxfs"))) {
|
||||
reader.readNextStartElement();
|
||||
if (reader.name() != QLatin1String("dxf"))
|
||||
return false;
|
||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("dxf"))
|
||||
readDxf(reader);
|
||||
}
|
||||
}
|
||||
if (reader.hasError())
|
||||
qWarning()<<reader.errorString();
|
||||
|
||||
if (hasCount && (count != m_dxf_formatsList.size()))
|
||||
qWarning("error read dxfs");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user