Fix the reading of style.xml
Save all the formats <xf>s in order even they are duplicated.
This commit is contained in:
@@ -77,8 +77,12 @@ Format *Styles::xfFormat(int idx) const
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Assign index to Font/Fill/Border and Format
|
Assign index to Font/Fill/Border and Format
|
||||||
|
|
||||||
|
When \a force is true, add the format to the format list, even other format has
|
||||||
|
the same key have been in.
|
||||||
|
This is useful when reading existing .xlsx files which may contains duplicated formats.
|
||||||
*/
|
*/
|
||||||
void Styles::addFormat(Format *format)
|
void Styles::addFormat(Format *format, bool force)
|
||||||
{
|
{
|
||||||
if (!format)
|
if (!format)
|
||||||
return;
|
return;
|
||||||
@@ -188,7 +192,7 @@ void Styles::addFormat(Format *format)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!format->xfIndexValid()) {
|
if (!format->xfIndexValid()) {
|
||||||
if (!m_xf_formatsHash.contains(format->formatKey())) {
|
if (!m_xf_formatsHash.contains(format->formatKey()) || force) {
|
||||||
format->setXfIndex(m_xf_formatsList.size());
|
format->setXfIndex(m_xf_formatsList.size());
|
||||||
m_xf_formatsList.append(format);
|
m_xf_formatsList.append(format);
|
||||||
m_xf_formatsHash[format->formatKey()] = format;
|
m_xf_formatsHash[format->formatKey()] = format;
|
||||||
@@ -926,7 +930,7 @@ bool Styles::readCellXfs(XmlStreamReader &reader)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addFormat(format);
|
addFormat(format, true);
|
||||||
|
|
||||||
//Find the endElement of xf
|
//Find the endElement of xf
|
||||||
while (!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("xf")))
|
while (!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("xf")))
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
Styles(bool createEmpty=false);
|
Styles(bool createEmpty=false);
|
||||||
~Styles();
|
~Styles();
|
||||||
Format *createFormat();
|
Format *createFormat();
|
||||||
void addFormat(Format *format);
|
void addFormat(Format *format, bool force=false);
|
||||||
Format *xfFormat(int idx) const;
|
Format *xfFormat(int idx) const;
|
||||||
|
|
||||||
QByteArray saveToXmlData();
|
QByteArray saveToXmlData();
|
||||||
|
|||||||
@@ -1475,7 +1475,7 @@ void WorksheetPrivate::readSheetData(XmlStreamReader &reader)
|
|||||||
int idx = attributes.value(QLatin1String("s")).toInt();
|
int idx = attributes.value(QLatin1String("s")).toInt();
|
||||||
format = workbook->styles()->xfFormat(idx);
|
format = workbook->styles()->xfFormat(idx);
|
||||||
if (!format)
|
if (!format)
|
||||||
qDebug()<<"Invalid style index: "<<idx;
|
qDebug()<<QStringLiteral("<c s=\"%1\">Invalid style index: ").arg(idx)<<idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributes.hasAttribute(QLatin1String("t"))) {
|
if (attributes.hasAttribute(QLatin1String("t"))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user