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