void SharedStrings::saveToXmlFile(QIODevice *device) const { QXmlStreamWriter writer(device); if (m_stringList.size() != m_stringTable.size()) { //Duplicated string items exist in m_stringList //Clean up can not be done here, as the indices //have been used when we save the worksheets part. } writer.writeStartDocument(QStringLiteral("1.0"), true); writer.writeStartElement(QStringLiteral("sst")); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); writer.writeAttribute(QStringLiteral("count"), QString::number(m_stringCount)); writer.writeAttribute(QStringLiteral("uniqueCount"), QString::number(m_stringList.size())); foreach (RichString string, m_stringList) { writer.writeStartElement(QStringLiteral("si")); if (string.isRichString()) { //Rich text string for (int i=0; i<string.fragmentCount(); ++i) { writer.writeStartElement(QStringLiteral("r")); if (string.fragmentFormat(i).hasFontData()) { writer.writeStartElement(QStringLiteral("rPr")); writeRichStringPart_rPr(writer, string.fragmentFormat(i)); writer.writeEndElement();// rPr } writer.writeStartElement(QStringLiteral("t")); if (isSpaceReserveNeeded(string.fragmentText(i))) writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve")); writer.writeCharacters(string.fragmentText(i)); writer.writeEndElement();// t writer.writeEndElement(); //r } } else { writer.writeStartElement(QStringLiteral("t")); QString pString = string.toPlainString(); if (isSpaceReserveNeeded(pString)) writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve")); writer.writeCharacters(pString); writer.writeEndElement();//t } writer.writeEndElement();//si }
void SharedStrings::saveToXmlFile(QIODevice *device) const { QXmlStreamWriter writer(device); writer.writeStartDocument(QStringLiteral("1.0"), true); writer.writeStartElement(QStringLiteral("sst")); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); writer.writeAttribute(QStringLiteral("count"), QString::number(m_stringCount)); writer.writeAttribute(QStringLiteral("uniqueCount"), QString::number(m_stringTable.size())); foreach (RichString string, m_stringList) { writer.writeStartElement(QStringLiteral("si")); if (string.isRichString()) { //Rich text string for (int i=0; i<string.fragmentCount(); ++i) { writer.writeStartElement(QStringLiteral("r")); if (string.fragmentFormat(i).hasFontData()) { writer.writeStartElement(QStringLiteral("rPr")); writeRichStringPart_rPr(writer, string.fragmentFormat(i)); writer.writeEndElement();// rPr } writer.writeStartElement(QStringLiteral("t")); if (string.fragmentText(i).contains(QRegularExpression(QStringLiteral("^\\s"))) || string.fragmentText(i).contains(QRegularExpression(QStringLiteral("\\s$")))) { writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve")); } writer.writeCharacters(string.fragmentText(i)); writer.writeEndElement();// t writer.writeEndElement(); //r } } else { writer.writeStartElement(QStringLiteral("t")); QString pString = string.toPlainString(); if (pString.contains(QRegularExpression(QStringLiteral("^\\s"))) || pString.contains(QRegularExpression(QStringLiteral("\\s$")))) { writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve")); } writer.writeCharacters(pString); writer.writeEndElement();//t } writer.writeEndElement();//si }