Browse Source

Wrap all char * string with QStringLiteral or QLatin1String

master
Debao Zhang 11 years ago
parent
commit
d87b50a4b7
  1. 56
      src/xlsx/xlsxcontenttypes.cpp
  2. 92
      src/xlsx/xlsxdocprops.cpp
  3. 22
      src/xlsx/xlsxformat.cpp
  4. 4
      src/xlsx/xlsxformat_p.h
  5. 42
      src/xlsx/xlsxpackage.cpp
  6. 26
      src/xlsx/xlsxrelationships.cpp
  7. 20
      src/xlsx/xlsxsharedstrings.cpp
  8. 282
      src/xlsx/xlsxstyles.cpp
  9. 6
      src/xlsx/xlsxutility.cpp
  10. 64
      src/xlsx/xlsxworkbook.cpp
  11. 112
      src/xlsx/xlsxworksheet.cpp

56
src/xlsx/xlsxcontenttypes.cpp

@ -31,17 +31,17 @@ namespace QXlsx {
ContentTypes::ContentTypes() ContentTypes::ContentTypes()
{ {
m_package_prefix = "application/vnd.openxmlformats-package."; m_package_prefix = QStringLiteral("application/vnd.openxmlformats-package.");
m_document_prefix = "application/vnd.openxmlformats-officedocument."; m_document_prefix = QStringLiteral("application/vnd.openxmlformats-officedocument.");
m_defaults.insert("rels", m_package_prefix + "relationships+xml"); m_defaults.insert(QStringLiteral("rels"), m_package_prefix + QStringLiteral("relationships+xml"));
m_defaults.insert("xml", "application/xml"); m_defaults.insert(QStringLiteral("xml"), QStringLiteral("application/xml"));
m_overrides.insert("/docProps/app.xml", m_document_prefix + "extended-properties+xml"); m_overrides.insert(QStringLiteral("/docProps/app.xml"), m_document_prefix + QStringLiteral("extended-properties+xml"));
m_overrides.insert("/docProps/core.xml", m_package_prefix + "core-properties+xml"); m_overrides.insert(QStringLiteral("/docProps/core.xml"), m_package_prefix + QStringLiteral("core-properties+xml"));
m_overrides.insert("/xl/styles.xml", m_document_prefix + "spreadsheetml.styles+xml"); m_overrides.insert(QStringLiteral("/xl/styles.xml"), m_document_prefix + QStringLiteral("spreadsheetml.styles+xml"));
m_overrides.insert("/xl/theme/theme1.xml", m_document_prefix + "theme+xml"); m_overrides.insert(QStringLiteral("/xl/theme/theme1.xml"), m_document_prefix + QStringLiteral("theme+xml"));
m_overrides.insert("/xl/workbook.xml", m_document_prefix + "spreadsheetml.sheet.main+xml"); m_overrides.insert(QStringLiteral("/xl/workbook.xml"), m_document_prefix + QStringLiteral("spreadsheetml.sheet.main+xml"));
} }
void ContentTypes::addDefault(const QString &key, const QString &value) void ContentTypes::addDefault(const QString &key, const QString &value)
@ -56,71 +56,71 @@ void ContentTypes::addOverride(const QString &key, const QString &value)
void ContentTypes::addWorksheetName(const QString &name) void ContentTypes::addWorksheetName(const QString &name)
{ {
addOverride(QString("/xl/worksheets/%1.xml").arg(name), m_document_prefix + "spreadsheetml.worksheet+xml"); addOverride(QStringLiteral("/xl/worksheets/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.worksheet+xml"));
} }
void ContentTypes::addChartsheetName(const QString &name) void ContentTypes::addChartsheetName(const QString &name)
{ {
addOverride(QString("/xl/chartsheets/%1.xml").arg(name), m_document_prefix + "spreadsheetml.chartsheet+xml"); addOverride(QStringLiteral("/xl/chartsheets/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.chartsheet+xml"));
} }
void ContentTypes::addChartName(const QString &name) void ContentTypes::addChartName(const QString &name)
{ {
addOverride(QString("/xl/charts/%1.xml").arg(name), m_document_prefix + "drawingml.chart+xml"); addOverride(QStringLiteral("/xl/charts/%1.xml").arg(name), m_document_prefix + QStringLiteral("drawingml.chart+xml"));
} }
void ContentTypes::addCommentName(const QString &name) void ContentTypes::addCommentName(const QString &name)
{ {
addOverride(QString("/xl/%1.xml").arg(name), m_document_prefix + "spreadsheetml.comments+xml"); addOverride(QStringLiteral("/xl/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.comments+xml"));
} }
void ContentTypes::addImageTypes(const QStringList &imageTypes) void ContentTypes::addImageTypes(const QStringList &imageTypes)
{ {
foreach (QString type, imageTypes) foreach (QString type, imageTypes)
addOverride(type, "image/" + type); addOverride(type, QStringLiteral("image/") + type);
} }
void ContentTypes::addTableName(const QString &name) void ContentTypes::addTableName(const QString &name)
{ {
addOverride(QString("/xl/tables/%1.xml").arg(name), m_document_prefix + "spreadsheetml.table+xml"); addOverride(QStringLiteral("/xl/tables/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.table+xml"));
} }
void ContentTypes::addSharedString() void ContentTypes::addSharedString()
{ {
addOverride("/xl/sharedStrings.xml", m_document_prefix + "spreadsheetml.sharedStrings+xml"); addOverride(QStringLiteral("/xl/sharedStrings.xml"), m_document_prefix + QStringLiteral("spreadsheetml.sharedStrings+xml"));
} }
void ContentTypes::addVmlName() void ContentTypes::addVmlName()
{ {
addOverride("vml", m_document_prefix + "vmlDrawing"); addOverride(QStringLiteral("vml"), m_document_prefix + QStringLiteral("vmlDrawing"));
} }
void ContentTypes::addCalcChain() void ContentTypes::addCalcChain()
{ {
addOverride("/xl/calcChain.xml", m_document_prefix + "spreadsheetml.calcChain+xml"); addOverride(QStringLiteral("/xl/calcChain.xml"), m_document_prefix + QStringLiteral("spreadsheetml.calcChain+xml"));
} }
void ContentTypes::addVbaProject() void ContentTypes::addVbaProject()
{ {
//:TODO //:TODO
addOverride("bin", "application/vnd.ms-office.vbaProject"); addOverride(QStringLiteral("bin"), QStringLiteral("application/vnd.ms-office.vbaProject"));
} }
void ContentTypes::saveToXmlFile(QIODevice *device) void ContentTypes::saveToXmlFile(QIODevice *device)
{ {
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("Types"); writer.writeStartElement(QStringLiteral("Types"));
writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/package/2006/content-types"); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/content-types"));
{ {
QMapIterator<QString, QString> it(m_defaults); QMapIterator<QString, QString> it(m_defaults);
while(it.hasNext()) { while(it.hasNext()) {
it.next(); it.next();
writer.writeStartElement("Default"); writer.writeStartElement(QStringLiteral("Default"));
writer.writeAttribute("Extension", it.key()); writer.writeAttribute(QStringLiteral("Extension"), it.key());
writer.writeAttribute("ContentType", it.value()); writer.writeAttribute(QStringLiteral("ContentType"), it.value());
writer.writeEndElement();//Default writer.writeEndElement();//Default
} }
} }
@ -129,9 +129,9 @@ void ContentTypes::saveToXmlFile(QIODevice *device)
QMapIterator<QString, QString> it(m_overrides); QMapIterator<QString, QString> it(m_overrides);
while(it.hasNext()) { while(it.hasNext()) {
it.next(); it.next();
writer.writeStartElement("Override"); writer.writeStartElement(QStringLiteral("Override"));
writer.writeAttribute("PartName", it.key()); writer.writeAttribute(QStringLiteral("PartName"), it.key());
writer.writeAttribute("ContentType", it.value()); writer.writeAttribute(QStringLiteral("ContentType"), it.value());
writer.writeEndElement(); //Override writer.writeEndElement(); //Override
} }
} }

92
src/xlsx/xlsxdocprops.cpp

@ -50,44 +50,44 @@ void DocProps::saveToXmlFile_App(QIODevice *device)
{ {
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("Properties"); writer.writeStartElement(QStringLiteral("Properties"));
writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
writer.writeAttribute("xmlns:vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); writer.writeAttribute(QStringLiteral("xmlns:vt"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"));
writer.writeTextElement("Application", "Microsoft Excel"); writer.writeTextElement(QStringLiteral("Application"), QStringLiteral("Microsoft Excel"));
writer.writeTextElement("DocSecurity", "0"); writer.writeTextElement(QStringLiteral("DocSecurity"), QStringLiteral("0"));
writer.writeTextElement("ScaleCrop", "false"); writer.writeTextElement(QStringLiteral("ScaleCrop"), QStringLiteral("false"));
writer.writeStartElement("HeadingPairs"); writer.writeStartElement(QStringLiteral("HeadingPairs"));
writer.writeStartElement("vt:vector"); writer.writeStartElement(QStringLiteral("vt:vector"));
writer.writeAttribute("size", QString::number(m_headingPairsList.size()*2)); writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size()*2));
writer.writeAttribute("baseType", "variant"); writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("variant"));
typedef QPair<QString,int> PairType; //Make foreach happy typedef QPair<QString,int> PairType; //Make foreach happy
foreach (PairType pair, m_headingPairsList) { foreach (PairType pair, m_headingPairsList) {
writer.writeStartElement("vt:variant"); writer.writeStartElement(QStringLiteral("vt:variant"));
writer.writeTextElement("vt:lpstr", pair.first); writer.writeTextElement(QStringLiteral("vt:lpstr"), pair.first);
writer.writeEndElement(); //vt:variant writer.writeEndElement(); //vt:variant
writer.writeStartElement("vt:variant"); writer.writeStartElement(QStringLiteral("vt:variant"));
writer.writeTextElement("vt:i4", QString::number(pair.second)); writer.writeTextElement(QStringLiteral("vt:i4"), QString::number(pair.second));
writer.writeEndElement(); //vt:variant writer.writeEndElement(); //vt:variant
} }
writer.writeEndElement();//vt:vector writer.writeEndElement();//vt:vector
writer.writeEndElement();//HeadingPairs writer.writeEndElement();//HeadingPairs
writer.writeStartElement("TitlesOfParts"); writer.writeStartElement(QStringLiteral("TitlesOfParts"));
writer.writeStartElement("vt:vector"); writer.writeStartElement(QStringLiteral("vt:vector"));
writer.writeAttribute("size", QString::number(m_titlesOfPartsList.size())); writer.writeAttribute(QStringLiteral("size"), QString::number(m_titlesOfPartsList.size()));
writer.writeAttribute("baseType", "lpstr"); writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("lpstr"));
foreach (QString title, m_titlesOfPartsList) foreach (QString title, m_titlesOfPartsList)
writer.writeTextElement("vt:lpstr", title); writer.writeTextElement(QStringLiteral("vt:lpstr"), title);
writer.writeEndElement();//vt:vector writer.writeEndElement();//vt:vector
writer.writeEndElement();//TitlesOfParts writer.writeEndElement();//TitlesOfParts
writer.writeTextElement("Company", ""); writer.writeTextElement(QStringLiteral("Company"), QStringLiteral(""));
writer.writeTextElement("LinksUpToDate", "false"); writer.writeTextElement(QStringLiteral("LinksUpToDate"), QStringLiteral("false"));
writer.writeTextElement("SharedDoc", "false"); writer.writeTextElement(QStringLiteral("SharedDoc"), QStringLiteral("false"));
writer.writeTextElement("HyperlinksChanged", "false"); writer.writeTextElement(QStringLiteral("HyperlinksChanged"), QStringLiteral("false"));
writer.writeTextElement("AppVersion", "12.0000"); writer.writeTextElement(QStringLiteral("AppVersion"), QStringLiteral("12.0000"));
writer.writeEndElement(); //Properties writer.writeEndElement(); //Properties
writer.writeEndDocument(); writer.writeEndDocument();
} }
@ -96,32 +96,32 @@ void DocProps::saveToXmlFile_Core(QIODevice *device)
{ {
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("cp:coreProperties"); writer.writeStartElement(QStringLiteral("cp:coreProperties"));
writer.writeAttribute("xmlns:cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); writer.writeAttribute(QStringLiteral("xmlns:cp"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"));
writer.writeAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); writer.writeAttribute(QStringLiteral("xmlns:dc"), QStringLiteral("http://purl.org/dc/elements/1.1/"));
writer.writeAttribute("xmlns:dcterms", "http://purl.org/dc/terms/"); writer.writeAttribute(QStringLiteral("xmlns:dcterms"), QStringLiteral("http://purl.org/dc/terms/"));
writer.writeAttribute("xmlns:dcmitype", "http://purl.org/dc/dcmitype/"); writer.writeAttribute(QStringLiteral("xmlns:dcmitype"), QStringLiteral("http://purl.org/dc/dcmitype/"));
writer.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.writeAttribute(QStringLiteral("xmlns:xsi"), QStringLiteral("http://www.w3.org/2001/XMLSchema-instance"));
writer.writeTextElement("dc:title", ""); writer.writeTextElement(QStringLiteral("dc:title"), QStringLiteral(""));
writer.writeTextElement("dc:subject", ""); writer.writeTextElement(QStringLiteral("dc:subject"), QStringLiteral(""));
writer.writeTextElement("dc:creator", "QXlsxWriter"); writer.writeTextElement(QStringLiteral("dc:creator"), QStringLiteral("QXlsxWriter"));
writer.writeTextElement("cp:keywords", ""); writer.writeTextElement(QStringLiteral("cp:keywords"), QStringLiteral(""));
writer.writeTextElement("dc:description", ""); writer.writeTextElement(QStringLiteral("dc:description"), QStringLiteral(""));
writer.writeTextElement("cp:lastModifiedBy", ""); writer.writeTextElement(QStringLiteral("cp:lastModifiedBy"), QStringLiteral(""));
writer.writeStartElement("dcterms:created"); writer.writeStartElement(QStringLiteral("dcterms:created"));
writer.writeAttribute("xsi:type", "dcterms:W3CDTF"); writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF"));
writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate));
writer.writeEndElement();//dcterms:created writer.writeEndElement();//dcterms:created
writer.writeStartElement("dcterms:modified"); writer.writeStartElement(QStringLiteral("dcterms:modified"));
writer.writeAttribute("xsi:type", "dcterms:W3CDTF"); writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF"));
writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate));
writer.writeEndElement();//dcterms:created writer.writeEndElement();//dcterms:created
writer.writeTextElement("cp:category", ""); writer.writeTextElement(QStringLiteral("cp:category"), QStringLiteral(""));
writer.writeTextElement("cp:contentStatus", ""); writer.writeTextElement(QStringLiteral("cp:contentStatus"), QStringLiteral(""));
writer.writeEndElement(); //cp:coreProperties writer.writeEndElement(); //cp:coreProperties
writer.writeEndDocument(); writer.writeEndDocument();
} }

22
src/xlsx/xlsxformat.cpp

@ -371,25 +371,25 @@ QString Format::horizontalAlignmentString() const
QString alignH; QString alignH;
switch (d->alignmentData.alignH) { switch (d->alignmentData.alignH) {
case Format::AlignLeft: case Format::AlignLeft:
alignH = "left"; alignH = QStringLiteral("left");
break; break;
case Format::AlignHCenter: case Format::AlignHCenter:
alignH = "center"; alignH = QStringLiteral("center");
break; break;
case Format::AlignRight: case Format::AlignRight:
alignH = "right"; alignH = QStringLiteral("right");
break; break;
case Format::AlignHFill: case Format::AlignHFill:
alignH = "fill"; alignH = QStringLiteral("fill");
break; break;
case Format::AlignHJustify: case Format::AlignHJustify:
alignH = "justify"; alignH = QStringLiteral("justify");
break; break;
case Format::AlignHMerge: case Format::AlignHMerge:
alignH = "centerContinuous"; alignH = QStringLiteral("centerContinuous");
break; break;
case Format::AlignHDistributed: case Format::AlignHDistributed:
alignH = "distributed"; alignH = QStringLiteral("distributed");
break; break;
default: default:
break; break;
@ -403,16 +403,16 @@ QString Format::verticalAlignmentString() const
QString align; QString align;
switch (d->alignmentData.alignV) { switch (d->alignmentData.alignV) {
case AlignTop: case AlignTop:
align = "top"; align = QStringLiteral("top");
break; break;
case AlignVCenter: case AlignVCenter:
align = "center"; align = QStringLiteral("center");
break; break;
case AlignVJustify: case AlignVJustify:
align = "justify"; align = QStringLiteral("justify");
break; break;
case AlignVDistributed: case AlignVDistributed:
align = "distributed"; align = QStringLiteral("distributed");
break; break;
default: default:
break; break;

4
src/xlsx/xlsxformat_p.h

@ -40,8 +40,8 @@ struct FontData
FontData() : FontData() :
size(11), italic(false), strikeOut(false), color(QColor()), bold(false) size(11), italic(false), strikeOut(false), color(QColor()), bold(false)
, scirpt(Format::FontScriptNormal), underline(Format::FontUnderlineNone) , scirpt(Format::FontScriptNormal), underline(Format::FontUnderlineNone)
, outline(false), shadow(false), name("Calibri"), family(2), charset(0) , outline(false), shadow(false), name(QStringLiteral("Calibri")), family(2), charset(0)
, scheme("minor"), condense(0), extend(0) , scheme(QStringLiteral("minor")), condense(0), extend(0)
, _dirty(true), _redundant(false), _index(-1) , _dirty(true), _redundant(false), _index(-1)
{} {}

42
src/xlsx/xlsxpackage.cpp

@ -126,7 +126,7 @@ void Package::writeWorksheetFiles(ZipWriter &zipWriter)
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
sheet->saveToXmlFile(&buffer); sheet->saveToXmlFile(&buffer);
zipWriter.addFile(QString("xl/worksheets/sheet%1.xml").arg(index), data); zipWriter.addFile(QStringLiteral("xl/worksheets/sheet%1.xml").arg(index), data);
index += 1; index += 1;
} }
} }
@ -137,7 +137,7 @@ void Package::writeWorkbookFile(ZipWriter &zipWriter)
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
m_workbook->saveToXmlFile(&buffer); m_workbook->saveToXmlFile(&buffer);
zipWriter.addFile("xl/workbook.xml", data); zipWriter.addFile(QStringLiteral("xl/workbook.xml"), data);
} }
void Package::writeContentTypesFiles(ZipWriter &zipWriter) void Package::writeContentTypesFiles(ZipWriter &zipWriter)
@ -149,7 +149,7 @@ void Package::writeContentTypesFiles(ZipWriter &zipWriter)
if (sheet->isChartsheet()) { if (sheet->isChartsheet()) {
} else { } else {
content.addWorksheetName(QString("sheet%1").arg(worksheet_index)); content.addWorksheetName(QStringLiteral("sheet%1").arg(worksheet_index));
worksheet_index += 1; worksheet_index += 1;
} }
} }
@ -161,7 +161,7 @@ void Package::writeContentTypesFiles(ZipWriter &zipWriter)
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
content.saveToXmlFile(&buffer); content.saveToXmlFile(&buffer);
zipWriter.addFile("[Content_Types].xml", data); zipWriter.addFile(QStringLiteral("[Content_Types].xml"), data);
} }
void Package::writeDocPropsFiles(ZipWriter &zipWriter) void Package::writeDocPropsFiles(ZipWriter &zipWriter)
@ -169,9 +169,9 @@ void Package::writeDocPropsFiles(ZipWriter &zipWriter)
DocProps props; DocProps props;
if (m_worksheet_count) if (m_worksheet_count)
props.addHeadingPair("Worksheets", m_worksheet_count); props.addHeadingPair(QStringLiteral("Worksheets"), m_worksheet_count);
if (m_chartsheet_count) if (m_chartsheet_count)
props.addHeadingPair("Chartsheets", m_chartsheet_count); props.addHeadingPair(QStringLiteral("Chartsheets"), m_chartsheet_count);
//Add worksheet parts //Add worksheet parts
foreach (Worksheet *sheet, m_workbook->worksheets()){ foreach (Worksheet *sheet, m_workbook->worksheets()){
@ -189,13 +189,13 @@ void Package::writeDocPropsFiles(ZipWriter &zipWriter)
QBuffer buffer1(&data1); QBuffer buffer1(&data1);
buffer1.open(QIODevice::WriteOnly); buffer1.open(QIODevice::WriteOnly);
props.saveToXmlFile_App(&buffer1); props.saveToXmlFile_App(&buffer1);
zipWriter.addFile("docProps/app.xml", data1); zipWriter.addFile(QStringLiteral("docProps/app.xml"), data1);
QByteArray data2; QByteArray data2;
QBuffer buffer2(&data2); QBuffer buffer2(&data2);
buffer2.open(QIODevice::WriteOnly); buffer2.open(QIODevice::WriteOnly);
props.saveToXmlFile_Core(&buffer2); props.saveToXmlFile_Core(&buffer2);
zipWriter.addFile("docProps/core.xml", data2); zipWriter.addFile(QStringLiteral("docProps/core.xml"), data2);
} }
void Package::writeSharedStringsFile(ZipWriter &zipWriter) void Package::writeSharedStringsFile(ZipWriter &zipWriter)
@ -204,7 +204,7 @@ void Package::writeSharedStringsFile(ZipWriter &zipWriter)
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
m_workbook->sharedStrings()->saveToXmlFile(&buffer); m_workbook->sharedStrings()->saveToXmlFile(&buffer);
zipWriter.addFile("xl/sharedStrings.xml", data); zipWriter.addFile(QStringLiteral("xl/sharedStrings.xml"), data);
} }
void Package::writeStylesFiles(ZipWriter &zipWriter) void Package::writeStylesFiles(ZipWriter &zipWriter)
@ -213,7 +213,7 @@ void Package::writeStylesFiles(ZipWriter &zipWriter)
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
m_workbook->styles()->saveToXmlFile(&buffer); m_workbook->styles()->saveToXmlFile(&buffer);
zipWriter.addFile("xl/styles.xml", data); zipWriter.addFile(QStringLiteral("xl/styles.xml"), data);
} }
void Package::writeThemeFile(ZipWriter &zipWriter) void Package::writeThemeFile(ZipWriter &zipWriter)
@ -222,21 +222,21 @@ void Package::writeThemeFile(ZipWriter &zipWriter)
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
Theme().saveToXmlFile(&buffer); Theme().saveToXmlFile(&buffer);
zipWriter.addFile("xl/theme/theme1.xml", data); zipWriter.addFile(QStringLiteral("xl/theme/theme1.xml"), data);
} }
void Package::writeRootRelsFile(ZipWriter &zipWriter) void Package::writeRootRelsFile(ZipWriter &zipWriter)
{ {
Relationships rels; Relationships rels;
rels.addDocumentRelationship("/officeDocument", "xl/workbook.xml"); rels.addDocumentRelationship(QStringLiteral("/officeDocument"), QStringLiteral("xl/workbook.xml"));
rels.addPackageRelationship("/metadata/core-properties", "docProps/core.xml"); rels.addPackageRelationship(QStringLiteral("/metadata/core-properties"), QStringLiteral("docProps/core.xml"));
rels.addDocumentRelationship("/extended-properties", "docProps/app.xml"); rels.addDocumentRelationship(QStringLiteral("/extended-properties"), QStringLiteral("docProps/app.xml"));
QByteArray data; QByteArray data;
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
rels.saveToXmlFile(&buffer); rels.saveToXmlFile(&buffer);
zipWriter.addFile("_rels/.rels", data); zipWriter.addFile(QStringLiteral("_rels/.rels"), data);
} }
void Package::writeWorkbookRelsFile(ZipWriter &zipWriter) void Package::writeWorkbookRelsFile(ZipWriter &zipWriter)
@ -247,25 +247,25 @@ void Package::writeWorkbookRelsFile(ZipWriter &zipWriter)
int chartsheet_index = 1; int chartsheet_index = 1;
foreach (Worksheet *sheet, m_workbook->worksheets()) { foreach (Worksheet *sheet, m_workbook->worksheets()) {
if (sheet->isChartsheet()) { if (sheet->isChartsheet()) {
rels.addDocumentRelationship("/chartsheet", QString("chartsheets/sheet%1.xml").arg(chartsheet_index)); rels.addDocumentRelationship(QStringLiteral("/chartsheet"), QStringLiteral("chartsheets/sheet%1.xml").arg(chartsheet_index));
chartsheet_index += 1; chartsheet_index += 1;
} else { } else {
rels.addDocumentRelationship("/worksheet", QString("worksheets/sheet%1.xml").arg(worksheet_index)); rels.addDocumentRelationship(QStringLiteral("/worksheet"), QStringLiteral("worksheets/sheet%1.xml").arg(worksheet_index));
worksheet_index += 1; worksheet_index += 1;
} }
} }
rels.addDocumentRelationship("/theme", "theme/theme1.xml"); rels.addDocumentRelationship(QStringLiteral("/theme"), QStringLiteral("theme/theme1.xml"));
rels.addDocumentRelationship("/styles", "styles.xml"); rels.addDocumentRelationship(QStringLiteral("/styles"), QStringLiteral("styles.xml"));
if (m_workbook->sharedStrings()->count()) if (m_workbook->sharedStrings()->count())
rels.addDocumentRelationship("/sharedStrings", "sharedStrings.xml"); rels.addDocumentRelationship(QStringLiteral("/sharedStrings"), QStringLiteral("sharedStrings.xml"));
QByteArray data; QByteArray data;
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
rels.saveToXmlFile(&buffer); rels.saveToXmlFile(&buffer);
zipWriter.addFile("xl/_rels/workbook.xml.rels", data); zipWriter.addFile(QStringLiteral("xl/_rels/workbook.xml.rels"), data);
} }
void Package::writeWorksheetRelsFile(ZipWriter &zipWriter) void Package::writeWorksheetRelsFile(ZipWriter &zipWriter)

26
src/xlsx/xlsxrelationships.cpp

@ -36,32 +36,32 @@ Relationships::Relationships(QObject *parent) :
void Relationships::addDocumentRelationship(const QString &relativeType, const QString &target) void Relationships::addDocumentRelationship(const QString &relativeType, const QString &target)
{ {
QString type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" + relativeType; QString type = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships") + relativeType;
addRelationship(type, target); addRelationship(type, target);
} }
void Relationships::addMsPackageRelationship(const QString &relativeType, const QString &target) void Relationships::addMsPackageRelationship(const QString &relativeType, const QString &target)
{ {
QString type = "http://schemas.microsoft.com/office/2006/relationships" + relativeType; QString type = QStringLiteral("http://schemas.microsoft.com/office/2006/relationships") + relativeType;
addRelationship(type, target); addRelationship(type, target);
} }
void Relationships::addPackageRelationship(const QString &relativeType, const QString &target) void Relationships::addPackageRelationship(const QString &relativeType, const QString &target)
{ {
QString type = "http://schemas.openxmlformats.org/package/2006/relationships" + relativeType; QString type = QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships") + relativeType;
addRelationship(type, target); addRelationship(type, target);
} }
void Relationships::addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode) void Relationships::addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode)
{ {
QString type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" + relativeType; QString type = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships") + relativeType;
addRelationship(type, target, targetMode); addRelationship(type, target, targetMode);
} }
void Relationships::addRelationship(const QString &type, const QString &target, const QString &targetMode) void Relationships::addRelationship(const QString &type, const QString &target, const QString &targetMode)
{ {
XlsxRelationship relation; XlsxRelationship relation;
relation.id = QString("rId%1").arg(m_relationships.size()+1); relation.id = QStringLiteral("rId%1").arg(m_relationships.size()+1);
relation.type = type; relation.type = type;
relation.target = target; relation.target = target;
relation.targetMode = targetMode; relation.targetMode = targetMode;
@ -73,16 +73,16 @@ void Relationships::saveToXmlFile(QIODevice *device)
{ {
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("Relationships"); writer.writeStartElement(QStringLiteral("Relationships"));
writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/package/2006/relationships"); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships"));
foreach (XlsxRelationship relation, m_relationships) { foreach (XlsxRelationship relation, m_relationships) {
writer.writeStartElement("Relationship"); writer.writeStartElement(QStringLiteral("Relationship"));
writer.writeAttribute("Id", relation.id); writer.writeAttribute(QStringLiteral("Id"), relation.id);
writer.writeAttribute("Type", relation.type); writer.writeAttribute(QStringLiteral("Type"), relation.type);
writer.writeAttribute("Target", relation.target); writer.writeAttribute(QStringLiteral("Target"), relation.target);
if (!relation.targetMode.isNull()) if (!relation.targetMode.isNull())
writer.writeAttribute("TargetMode", relation.targetMode); writer.writeAttribute(QStringLiteral("TargetMode"), relation.targetMode);
writer.writeEndElement(); writer.writeEndElement();
} }
writer.writeEndElement();//Relationships writer.writeEndElement();//Relationships

20
src/xlsx/xlsxsharedstrings.cpp

@ -74,21 +74,21 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const
{ {
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("sst"); writer.writeStartElement(QStringLiteral("sst"));
writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute("count", QString::number(m_stringCount)); writer.writeAttribute(QStringLiteral("count"), QString::number(m_stringCount));
writer.writeAttribute("uniqueCount", QString::number(m_stringTable.size())); writer.writeAttribute(QStringLiteral("uniqueCount"), QString::number(m_stringTable.size()));
foreach (QString string, m_stringList) { foreach (QString string, m_stringList) {
writer.writeStartElement("si"); writer.writeStartElement(QStringLiteral("si"));
if (string.contains(QRegularExpression("^<r>")) || string.contains(QRegularExpression("</r>$"))) { if (string.contains(QRegularExpression(QStringLiteral("^<r>"))) || string.contains(QRegularExpression(QStringLiteral("</r>$")))) {
//Rich text string, //Rich text string,
// writer.writeCharacters(string); // writer.writeCharacters(string);
} else { } else {
writer.writeStartElement("t"); writer.writeStartElement(QStringLiteral("t"));
if (string.contains(QRegularExpression("^\\s")) || string.contains(QRegularExpression("\\s$"))) if (string.contains(QRegularExpression(QStringLiteral("^\\s"))) || string.contains(QRegularExpression(QStringLiteral("\\s$"))))
writer.writeAttribute("xml:space", "preserve"); writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
writer.writeCharacters(string); writer.writeCharacters(string);
writer.writeEndElement();//t writer.writeEndElement();//t
} }

282
src/xlsx/xlsxstyles.cpp

@ -141,44 +141,44 @@ void Styles::saveToXmlFile(QIODevice *device)
{ {
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("styleSheet"); writer.writeStartElement(QStringLiteral("styleSheet"));
writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
// writer.writeStartElement("numFmts"); // writer.writeStartElement(QStringLiteral("numFmts"));
// writer.writeEndElement();//numFmts // writer.writeEndElement();//numFmts
writeFonts(writer); writeFonts(writer);
writeFills(writer); writeFills(writer);
writeBorders(writer); writeBorders(writer);
writer.writeStartElement("cellStyleXfs"); writer.writeStartElement(QStringLiteral("cellStyleXfs"));
writer.writeAttribute("count", "1"); writer.writeAttribute(QStringLiteral("count"), QStringLiteral("1"));
writer.writeStartElement("xf"); writer.writeStartElement(QStringLiteral("xf"));
writer.writeAttribute("numFmtId", "0"); writer.writeAttribute(QStringLiteral("numFmtId"), QStringLiteral("0"));
writer.writeAttribute("fontId", "0"); writer.writeAttribute(QStringLiteral("fontId"), QStringLiteral("0"));
writer.writeAttribute("fillId", "0"); writer.writeAttribute(QStringLiteral("fillId"), QStringLiteral("0"));
writer.writeAttribute("borderId", "0"); writer.writeAttribute(QStringLiteral("borderId"), QStringLiteral("0"));
writer.writeEndElement();//xf writer.writeEndElement();//xf
writer.writeEndElement();//cellStyleXfs writer.writeEndElement();//cellStyleXfs
writeCellXfs(writer); writeCellXfs(writer);
writer.writeStartElement("cellStyles"); writer.writeStartElement(QStringLiteral("cellStyles"));
writer.writeAttribute("count", "1"); writer.writeAttribute(QStringLiteral("count"), QStringLiteral("1"));
writer.writeStartElement("cellStyle"); writer.writeStartElement(QStringLiteral("cellStyle"));
writer.writeAttribute("name", "Normal"); writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Normal"));
writer.writeAttribute("xfId", "0"); writer.writeAttribute(QStringLiteral("xfId"), QStringLiteral("0"));
writer.writeAttribute("builtinId", "0"); writer.writeAttribute(QStringLiteral("builtinId"), QStringLiteral("0"));
writer.writeEndElement();//cellStyle writer.writeEndElement();//cellStyle
writer.writeEndElement();//cellStyles writer.writeEndElement();//cellStyles
writeDxfs(writer); writeDxfs(writer);
writer.writeStartElement("tableStyles"); writer.writeStartElement(QStringLiteral("tableStyles"));
writer.writeAttribute("count", "0"); writer.writeAttribute(QStringLiteral("count"), QStringLiteral("0"));
writer.writeAttribute("defaultTableStyle", "TableStyleMedium9"); writer.writeAttribute(QStringLiteral("defaultTableStyle"), QStringLiteral("TableStyleMedium9"));
writer.writeAttribute("defaultPivotStyle", "PivotStyleLight16"); writer.writeAttribute(QStringLiteral("defaultPivotStyle"), QStringLiteral("PivotStyleLight16"));
writer.writeEndElement();//tableStyles writer.writeEndElement();//tableStyles
writer.writeEndElement();//styleSheet writer.writeEndElement();//styleSheet
@ -188,67 +188,67 @@ void Styles::saveToXmlFile(QIODevice *device)
void Styles::writeFonts(XmlStreamWriter &writer) void Styles::writeFonts(XmlStreamWriter &writer)
{ {
writer.writeStartElement("fonts"); writer.writeStartElement(QStringLiteral("fonts"));
writer.writeAttribute("count", QString::number(m_font_count)); writer.writeAttribute(QStringLiteral("count"), QString::number(m_font_count));
foreach (Format *format, m_xf_formats) { foreach (Format *format, m_xf_formats) {
if (format->hasFont()) { if (format->hasFont()) {
writer.writeStartElement("font"); writer.writeStartElement(QStringLiteral("font"));
if (format->fontBold()) if (format->fontBold())
writer.writeEmptyElement("b"); writer.writeEmptyElement(QStringLiteral("b"));
if (format->fontItalic()) if (format->fontItalic())
writer.writeEmptyElement("i"); writer.writeEmptyElement(QStringLiteral("i"));
if (format->fontStrikeOut()) if (format->fontStrikeOut())
writer.writeEmptyElement("strike"); writer.writeEmptyElement(QStringLiteral("strike"));
if (format->fontOutline()) if (format->fontOutline())
writer.writeEmptyElement("outline"); writer.writeEmptyElement(QStringLiteral("outline"));
if (format->fontShadow()) if (format->fontShadow())
writer.writeEmptyElement("shadow"); writer.writeEmptyElement(QStringLiteral("shadow"));
if (format->fontUnderline() != Format::FontUnderlineNone) { if (format->fontUnderline() != Format::FontUnderlineNone) {
writer.writeEmptyElement("u"); writer.writeEmptyElement(QStringLiteral("u"));
if (format->fontUnderline() == Format::FontUnderlineDouble) if (format->fontUnderline() == Format::FontUnderlineDouble)
writer.writeAttribute("val", "double"); writer.writeAttribute(QStringLiteral("val"), QStringLiteral("double"));
else if (format->fontUnderline() == Format::FontUnderlineSingleAccounting) else if (format->fontUnderline() == Format::FontUnderlineSingleAccounting)
writer.writeAttribute("val", "singleAccounting"); writer.writeAttribute(QStringLiteral("val"), QStringLiteral("singleAccounting"));
else if (format->fontUnderline() == Format::FontUnderlineDoubleAccounting) else if (format->fontUnderline() == Format::FontUnderlineDoubleAccounting)
writer.writeAttribute("val", "doubleAccounting"); writer.writeAttribute(QStringLiteral("val"), QStringLiteral("doubleAccounting"));
} }
if (format->fontScript() != Format::FontScriptNormal) { if (format->fontScript() != Format::FontScriptNormal) {
writer.writeEmptyElement("vertAligh"); writer.writeEmptyElement(QStringLiteral("vertAligh"));
if (format->fontScript() == Format::FontScriptSuper) if (format->fontScript() == Format::FontScriptSuper)
writer.writeAttribute("val", "superscript"); writer.writeAttribute(QStringLiteral("val"), QStringLiteral("superscript"));
else else
writer.writeAttribute("val", "subscript"); writer.writeAttribute(QStringLiteral("val"), QStringLiteral("subscript"));
} }
if (!format->isDxfFormat()) { if (!format->isDxfFormat()) {
writer.writeEmptyElement("sz"); writer.writeEmptyElement(QStringLiteral("sz"));
writer.writeAttribute("val", QString::number(format->fontSize())); writer.writeAttribute(QStringLiteral("val"), QString::number(format->fontSize()));
} }
//font color //font color
if (format->theme()) { if (format->theme()) {
writer.writeEmptyElement("color"); writer.writeEmptyElement(QStringLiteral("color"));
writer.writeAttribute("theme", QString::number(format->theme())); writer.writeAttribute(QStringLiteral("theme"), QString::number(format->theme()));
} else if (format->colorIndexed()) { } else if (format->colorIndexed()) {
writer.writeEmptyElement("color"); writer.writeEmptyElement(QStringLiteral("color"));
writer.writeAttribute("indexed", QString::number(format->colorIndexed())); writer.writeAttribute(QStringLiteral("indexed"), QString::number(format->colorIndexed()));
} else if (format->fontColor().isValid()) { } else if (format->fontColor().isValid()) {
writer.writeEmptyElement("color"); writer.writeEmptyElement(QStringLiteral("color"));
QString color = format->fontColor().name(); QString color = format->fontColor().name();
writer.writeAttribute("rgb", "FF"+color.mid(1));//remove # writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.mid(1));//remove #
} else if (!format->isDxfFormat()) { } else if (!format->isDxfFormat()) {
writer.writeEmptyElement("color"); writer.writeEmptyElement(QStringLiteral("color"));
writer.writeAttribute("theme", "1"); writer.writeAttribute(QStringLiteral("theme"), QStringLiteral("1"));
} }
if (!format->isDxfFormat()) { if (!format->isDxfFormat()) {
writer.writeEmptyElement("name"); writer.writeEmptyElement(QStringLiteral("name"));
writer.writeAttribute("val", format->fontName()); writer.writeAttribute(QStringLiteral("val"), format->fontName());
writer.writeEmptyElement("family"); writer.writeEmptyElement(QStringLiteral("family"));
writer.writeAttribute("val", QString::number(format->fontFamily())); writer.writeAttribute(QStringLiteral("val"), QString::number(format->fontFamily()));
if (format->fontName() == "Calibri") { if (format->fontName() == QLatin1String("Calibri")) {
writer.writeEmptyElement("scheme"); writer.writeEmptyElement(QStringLiteral("scheme"));
writer.writeAttribute("val", format->fontScheme()); writer.writeAttribute(QStringLiteral("val"), format->fontScheme());
} }
} }
@ -260,16 +260,16 @@ void Styles::writeFonts(XmlStreamWriter &writer)
void Styles::writeFills(XmlStreamWriter &writer) void Styles::writeFills(XmlStreamWriter &writer)
{ {
writer.writeStartElement("fills"); writer.writeStartElement(QStringLiteral("fills"));
writer.writeAttribute("count", QString::number(m_fill_count)); writer.writeAttribute(QStringLiteral("count"), QString::number(m_fill_count));
//wirte two default fill first //wirte two default fill first
writer.writeStartElement("fill"); writer.writeStartElement(QStringLiteral("fill"));
writer.writeEmptyElement("patternFill"); writer.writeEmptyElement(QStringLiteral("patternFill"));
writer.writeAttribute("patternType", "none"); writer.writeAttribute(QStringLiteral("patternType"), QStringLiteral("none"));
writer.writeEndElement();//fill writer.writeEndElement();//fill
writer.writeStartElement("fill"); writer.writeStartElement(QStringLiteral("fill"));
writer.writeEmptyElement("patternFill"); writer.writeEmptyElement(QStringLiteral("patternFill"));
writer.writeAttribute("patternType", "gray125"); writer.writeAttribute(QStringLiteral("patternType"), QStringLiteral("gray125"));
writer.writeEndElement();//fill writer.writeEndElement();//fill
foreach (Format *format, m_xf_formats) { foreach (Format *format, m_xf_formats) {
if (format->hasFill()) { if (format->hasFill()) {
@ -283,36 +283,36 @@ void Styles::writeFill(XmlStreamWriter &writer, Format *format)
{ {
static QMap<int, QString> patternStrings; static QMap<int, QString> patternStrings;
if (patternStrings.isEmpty()) { if (patternStrings.isEmpty()) {
patternStrings[Format::PatternNone] = "none"; patternStrings[Format::PatternNone] = QStringLiteral("none");
patternStrings[Format::PatternSolid] = "solid"; patternStrings[Format::PatternSolid] = QStringLiteral("solid");
patternStrings[Format::PatternMediumGray] = "mediumGray"; patternStrings[Format::PatternMediumGray] = QStringLiteral("mediumGray");
patternStrings[Format::PatternDarkGray] = "darkGray"; patternStrings[Format::PatternDarkGray] = QStringLiteral("darkGray");
patternStrings[Format::PatternLightGray] = "lightGray"; patternStrings[Format::PatternLightGray] = QStringLiteral("lightGray");
patternStrings[Format::PatternDarkHorizontal] = "darkHorizontal"; patternStrings[Format::PatternDarkHorizontal] = QStringLiteral("darkHorizontal");
patternStrings[Format::PatternDarkVertical] = "darkVertical"; patternStrings[Format::PatternDarkVertical] = QStringLiteral("darkVertical");
patternStrings[Format::PatternDarkDown] = "darkDown"; patternStrings[Format::PatternDarkDown] = QStringLiteral("darkDown");
patternStrings[Format::PatternDarkUp] = "darkUp"; patternStrings[Format::PatternDarkUp] = QStringLiteral("darkUp");
patternStrings[Format::PatternDarkGrid] = "darkGrid"; patternStrings[Format::PatternDarkGrid] = QStringLiteral("darkGrid");
patternStrings[Format::PatternDarkTrellis] = "darkTrellis"; patternStrings[Format::PatternDarkTrellis] = QStringLiteral("darkTrellis");
patternStrings[Format::PatternLightHorizontal] = "lightHorizontal"; patternStrings[Format::PatternLightHorizontal] = QStringLiteral("lightHorizontal");
patternStrings[Format::PatternLightVertical] = "lightVertical"; patternStrings[Format::PatternLightVertical] = QStringLiteral("lightVertical");
patternStrings[Format::PatternLightDown] = "lightDown"; patternStrings[Format::PatternLightDown] = QStringLiteral("lightDown");
patternStrings[Format::PatternLightUp] = "lightUp"; patternStrings[Format::PatternLightUp] = QStringLiteral("lightUp");
patternStrings[Format::PatternLightTrellis] = "lightTrellis"; patternStrings[Format::PatternLightTrellis] = QStringLiteral("lightTrellis");
patternStrings[Format::PatternGray125] = "gray125"; patternStrings[Format::PatternGray125] = QStringLiteral("gray125");
patternStrings[Format::PatternGray0625] = "gray0625"; patternStrings[Format::PatternGray0625] = QStringLiteral("gray0625");
} }
writer.writeStartElement("fill"); writer.writeStartElement(QStringLiteral("fill"));
writer.writeStartElement("patternFill"); writer.writeStartElement(QStringLiteral("patternFill"));
writer.writeAttribute("patternType", patternStrings[format->fillPattern()]); writer.writeAttribute(QStringLiteral("patternType"), patternStrings[format->fillPattern()]);
if (format->patternForegroundColor().isValid()) { if (format->patternForegroundColor().isValid()) {
writer.writeEmptyElement("fgColor"); writer.writeEmptyElement(QStringLiteral("fgColor"));
writer.writeAttribute("rgb", "FF"+format->patternForegroundColor().name().mid(1)); writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+format->patternForegroundColor().name().mid(1));
} }
if (format->patternBackgroundColor().isValid()) { if (format->patternBackgroundColor().isValid()) {
writer.writeEmptyElement("bgColor"); writer.writeEmptyElement(QStringLiteral("bgColor"));
writer.writeAttribute("rgb", "FF"+format->patternBackgroundColor().name().mid(1)); writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+format->patternBackgroundColor().name().mid(1));
} }
writer.writeEndElement();//patternFill writer.writeEndElement();//patternFill
@ -321,26 +321,26 @@ void Styles::writeFill(XmlStreamWriter &writer, Format *format)
void Styles::writeBorders(XmlStreamWriter &writer) void Styles::writeBorders(XmlStreamWriter &writer)
{ {
writer.writeStartElement("borders"); writer.writeStartElement(QStringLiteral("borders"));
writer.writeAttribute("count", QString::number(m_borders_count)); writer.writeAttribute(QStringLiteral("count"), QString::number(m_borders_count));
foreach (Format *format, m_xf_formats) { foreach (Format *format, m_xf_formats) {
if (format->hasBorders()) { if (format->hasBorders()) {
writer.writeStartElement("border"); writer.writeStartElement(QStringLiteral("border"));
if (format->diagonalBorderType() == Format::DiagonalBorderUp) { if (format->diagonalBorderType() == Format::DiagonalBorderUp) {
writer.writeAttribute("diagonalUp", "1"); writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1"));
} else if (format->diagonalBorderType() == Format::DiagonalBorderDown) { } else if (format->diagonalBorderType() == Format::DiagonalBorderDown) {
writer.writeAttribute("diagonalDown", "1"); writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1"));
} else if (format->DiagnoalBorderBoth) { } else if (format->DiagnoalBorderBoth) {
writer.writeAttribute("diagonalUp", "1"); writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1"));
writer.writeAttribute("diagonalDown", "1"); writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1"));
} }
writeSubBorder(writer, "left", format->leftBorderStyle(), format->leftBorderColor()); writeSubBorder(writer, QStringLiteral("left"), format->leftBorderStyle(), format->leftBorderColor());
writeSubBorder(writer, "right", format->rightBorderStyle(), format->rightBorderColor()); writeSubBorder(writer, QStringLiteral("right"), format->rightBorderStyle(), format->rightBorderColor());
writeSubBorder(writer, "top", format->topBorderStyle(), format->topBorderColor()); writeSubBorder(writer, QStringLiteral("top"), format->topBorderStyle(), format->topBorderColor());
writeSubBorder(writer, "bottom", format->bottomBorderStyle(), format->bottomBorderColor()); writeSubBorder(writer, QStringLiteral("bottom"), format->bottomBorderStyle(), format->bottomBorderColor());
if (!format->isDxfFormat()) { if (!format->isDxfFormat()) {
writeSubBorder(writer, "diagonal", format->diagonalBorderStyle(), format->diagonalBorderColor()); writeSubBorder(writer, QStringLiteral("diagonal"), format->diagonalBorderStyle(), format->diagonalBorderColor());
} }
writer.writeEndElement();//border writer.writeEndElement();//border
} }
@ -357,75 +357,75 @@ void Styles::writeSubBorder(XmlStreamWriter &writer, const QString &type, int st
static QMap<int, QString> stylesString; static QMap<int, QString> stylesString;
if (stylesString.isEmpty()) { if (stylesString.isEmpty()) {
stylesString[Format::BorderNone] = "none"; stylesString[Format::BorderNone] = QStringLiteral("none");
stylesString[Format::BorderThin] = "thin"; stylesString[Format::BorderThin] = QStringLiteral("thin");
stylesString[Format::BorderMedium] = "medium"; stylesString[Format::BorderMedium] = QStringLiteral("medium");
stylesString[Format::BorderDashed] = "dashed"; stylesString[Format::BorderDashed] = QStringLiteral("dashed");
stylesString[Format::BorderDotted] = "dotted"; stylesString[Format::BorderDotted] = QStringLiteral("dotted");
stylesString[Format::BorderThick] = "thick"; stylesString[Format::BorderThick] = QStringLiteral("thick");
stylesString[Format::BorderDouble] = "double"; stylesString[Format::BorderDouble] = QStringLiteral("double");
stylesString[Format::BorderHair] = "hair"; stylesString[Format::BorderHair] = QStringLiteral("hair");
stylesString[Format::BorderMediumDashed] = "mediumDashed"; stylesString[Format::BorderMediumDashed] = QStringLiteral("mediumDashed");
stylesString[Format::BorderDashDot] = "dashDot"; stylesString[Format::BorderDashDot] = QStringLiteral("dashDot");
stylesString[Format::BorderMediumDashDot] = "mediumDashDot"; stylesString[Format::BorderMediumDashDot] = QStringLiteral("mediumDashDot");
stylesString[Format::BorderDashDotDot] = "dashDotDot"; stylesString[Format::BorderDashDotDot] = QStringLiteral("dashDotDot");
stylesString[Format::BorderMediumDashDotDot] = "mediumDashDotDot"; stylesString[Format::BorderMediumDashDotDot] = QStringLiteral("mediumDashDotDot");
stylesString[Format::BorderSlantDashDot] = "slantDashDot"; stylesString[Format::BorderSlantDashDot] = QStringLiteral("slantDashDot");
} }
writer.writeStartElement(type); writer.writeStartElement(type);
writer.writeAttribute("style", stylesString[style]); writer.writeAttribute(QStringLiteral("style"), stylesString[style]);
writer.writeEmptyElement("color"); writer.writeEmptyElement(QStringLiteral("color"));
if (color.isValid()) if (color.isValid())
writer.writeAttribute("rgb", "FF"+color.name().mid(1)); //remove # writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.name().mid(1)); //remove #
else else
writer.writeAttribute("auto", "1"); writer.writeAttribute(QStringLiteral("auto"), QStringLiteral("1"));
writer.writeEndElement();//type writer.writeEndElement();//type
} }
void Styles::writeCellXfs(XmlStreamWriter &writer) void Styles::writeCellXfs(XmlStreamWriter &writer)
{ {
writer.writeStartElement("cellXfs"); writer.writeStartElement(QStringLiteral("cellXfs"));
writer.writeAttribute("count", QString::number(m_xf_formats.size())); writer.writeAttribute(QStringLiteral("count"), QString::number(m_xf_formats.size()));
foreach (Format *format, m_xf_formats) { foreach (Format *format, m_xf_formats) {
int num_fmt_id = format->numberFormat(); int num_fmt_id = format->numberFormat();
int font_id = format->fontIndex(); int font_id = format->fontIndex();
int fill_id = format->fillIndex(); int fill_id = format->fillIndex();
int border_id = format->borderIndex(); int border_id = format->borderIndex();
int xf_id = 0; int xf_id = 0;
writer.writeStartElement("xf"); writer.writeStartElement(QStringLiteral("xf"));
writer.writeAttribute("numFmtId", QString::number(num_fmt_id)); writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(num_fmt_id));
writer.writeAttribute("fontId", QString::number(font_id)); writer.writeAttribute(QStringLiteral("fontId"), QString::number(font_id));
writer.writeAttribute("fillId", QString::number(fill_id)); writer.writeAttribute(QStringLiteral("fillId"), QString::number(fill_id));
writer.writeAttribute("borderId", QString::number(border_id)); writer.writeAttribute(QStringLiteral("borderId"), QString::number(border_id));
writer.writeAttribute("xfId", QString::number(xf_id)); writer.writeAttribute(QStringLiteral("xfId"), QString::number(xf_id));
if (format->numberFormat() > 0) if (format->numberFormat() > 0)
writer.writeAttribute("applyNumberFormat", "1"); writer.writeAttribute(QStringLiteral("applyNumberFormat"), QStringLiteral("1"));
if (format->fontIndex() > 0) if (format->fontIndex() > 0)
writer.writeAttribute("applyFont", "1"); writer.writeAttribute(QStringLiteral("applyFont"), QStringLiteral("1"));
if (format->borderIndex() > 0) if (format->borderIndex() > 0)
writer.writeAttribute("applyBorder", "1"); writer.writeAttribute(QStringLiteral("applyBorder"), QStringLiteral("1"));
if (format->fillIndex() > 0) if (format->fillIndex() > 0)
writer.writeAttribute("applyFill", "1"); writer.writeAttribute(QStringLiteral("applyFill"), QStringLiteral("1"));
if (format->alignmentChanged()) if (format->alignmentChanged())
writer.writeAttribute("applyAlignment", "1"); writer.writeAttribute(QStringLiteral("applyAlignment"), QStringLiteral("1"));
if (format->alignmentChanged()) { if (format->alignmentChanged()) {
writer.writeEmptyElement("alignment"); writer.writeEmptyElement(QStringLiteral("alignment"));
QString alignH = format->horizontalAlignmentString(); QString alignH = format->horizontalAlignmentString();
if (!alignH.isEmpty()) if (!alignH.isEmpty())
writer.writeAttribute("horizontal", alignH); writer.writeAttribute(QStringLiteral("horizontal"), alignH);
QString alignV = format->verticalAlignmentString(); QString alignV = format->verticalAlignmentString();
if (!alignV.isEmpty()) if (!alignV.isEmpty())
writer.writeAttribute("vertical", alignV); writer.writeAttribute(QStringLiteral("vertical"), alignV);
if (format->indent()) if (format->indent())
writer.writeAttribute("indent", QString::number(format->indent())); writer.writeAttribute(QStringLiteral("indent"), QString::number(format->indent()));
if (format->textWrap()) if (format->textWrap())
writer.writeAttribute("wrapText", "1"); writer.writeAttribute(QStringLiteral("wrapText"), QStringLiteral("1"));
if (format->shrinkToFit()) if (format->shrinkToFit())
writer.writeAttribute("shrinkToFit", "1"); writer.writeAttribute(QStringLiteral("shrinkToFit"), QStringLiteral("1"));
if (format->shrinkToFit()) if (format->shrinkToFit())
writer.writeAttribute("shrinkToFit", "1"); writer.writeAttribute(QStringLiteral("shrinkToFit"), QStringLiteral("1"));
} }
writer.writeEndElement();//xf writer.writeEndElement();//xf
@ -435,10 +435,10 @@ void Styles::writeCellXfs(XmlStreamWriter &writer)
void Styles::writeDxfs(XmlStreamWriter &writer) void Styles::writeDxfs(XmlStreamWriter &writer)
{ {
writer.writeStartElement("dxfs"); writer.writeStartElement(QStringLiteral("dxfs"));
writer.writeAttribute("count", QString::number(m_dxf_formats.size())); writer.writeAttribute(QStringLiteral("count"), QString::number(m_dxf_formats.size()));
foreach (Format *format, m_dxf_formats) { foreach (Format *format, m_dxf_formats) {
writer.writeStartElement("dxf"); writer.writeStartElement(QStringLiteral("dxf"));
writer.writeEndElement();//dxf writer.writeEndElement();//dxf
} }
writer.writeEndElement(); //dxfs writer.writeEndElement(); //dxfs

6
src/xlsx/xlsxutility.cpp

@ -45,7 +45,7 @@ QPoint xl_cell_to_rowcol(const QString &cell_str)
{ {
if (cell_str.isEmpty()) if (cell_str.isEmpty())
return QPoint(0, 0); return QPoint(0, 0);
QRegularExpression re("^([A-Z]{1,3})(\\d+)$"); QRegularExpression re(QStringLiteral("^([A-Z]{1,3})(\\d+)$"));
QRegularExpressionMatch match = re.match(cell_str); QRegularExpressionMatch match = re.match(cell_str);
if (match.hasMatch()) { if (match.hasMatch()) {
QString col_str = match.captured(1); QString col_str = match.captured(1);
@ -87,10 +87,10 @@ QString xl_rowcol_to_cell(int row, int col, bool row_abs, bool col_abs)
row += 1; //Change to 1-index row += 1; //Change to 1-index
QString cell_str; QString cell_str;
if (col_abs) if (col_abs)
cell_str.append("$"); cell_str.append(QLatin1Char('$'));
cell_str.append(xl_col_to_name(col)); cell_str.append(xl_col_to_name(col));
if (row_abs) if (row_abs)
cell_str.append("$"); cell_str.append(QLatin1Char('$'));
cell_str.append(QString::number(row)); cell_str.append(QString::number(row));
return cell_str; return cell_str;
} }

64
src/xlsx/xlsxworkbook.cpp

@ -137,7 +137,7 @@ Worksheet *Workbook::addWorksheet(const QString &name)
QString worksheetName = name; QString worksheetName = name;
int index = d->worksheets.size()+1; int index = d->worksheets.size()+1;
if (name.isEmpty()) if (name.isEmpty())
worksheetName = QString("Sheet%1").arg(index); worksheetName = QStringLiteral("Sheet%1").arg(index);
Worksheet *sheet = new Worksheet(worksheetName, index, this); Worksheet *sheet = new Worksheet(worksheetName, index, this);
d->worksheets.append(sheet); d->worksheets.append(sheet);
@ -173,53 +173,53 @@ void Workbook::saveToXmlFile(QIODevice *device)
Q_D(Workbook); Q_D(Workbook);
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("workbook"); writer.writeStartElement(QStringLiteral("workbook"));
writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute("xmlns:r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeEmptyElement("fileVersion"); writer.writeEmptyElement(QStringLiteral("fileVersion"));
writer.writeAttribute("appName", "xl"); writer.writeAttribute(QStringLiteral("appName"), QStringLiteral("xl"));
writer.writeAttribute("lastEdited", "4"); writer.writeAttribute(QStringLiteral("lastEdited"), QStringLiteral("4"));
writer.writeAttribute("lowestEdited", "4"); writer.writeAttribute(QStringLiteral("lowestEdited"), QStringLiteral("4"));
writer.writeAttribute("rupBuild", "4505"); writer.writeAttribute(QStringLiteral("rupBuild"), QStringLiteral("4505"));
// writer.writeAttribute("codeName", "{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}"); // writer.writeAttribute(QStringLiteral("codeName"), QStringLiteral("{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}"));
writer.writeEmptyElement("workbookPr"); writer.writeEmptyElement(QStringLiteral("workbookPr"));
if (d->date1904) if (d->date1904)
writer.writeAttribute("date1904", "1"); writer.writeAttribute(QStringLiteral("date1904"), QStringLiteral("1"));
writer.writeAttribute("defaultThemeVersion", "124226"); writer.writeAttribute(QStringLiteral("defaultThemeVersion"), QStringLiteral("124226"));
writer.writeStartElement("bookViews"); writer.writeStartElement(QStringLiteral("bookViews"));
writer.writeEmptyElement("workbookView"); writer.writeEmptyElement(QStringLiteral("workbookView"));
writer.writeAttribute("xWindow", QString::number(d->x_window)); writer.writeAttribute(QStringLiteral("xWindow"), QString::number(d->x_window));
writer.writeAttribute("yWindow", QString::number(d->y_window)); writer.writeAttribute(QStringLiteral("yWindow"), QString::number(d->y_window));
writer.writeAttribute("windowWidth", QString::number(d->window_width)); writer.writeAttribute(QStringLiteral("windowWidth"), QString::number(d->window_width));
writer.writeAttribute("windowHeight", QString::number(d->window_height)); writer.writeAttribute(QStringLiteral("windowHeight"), QString::number(d->window_height));
//Store the firstSheet when it isn't the default //Store the firstSheet when it isn't the default
if (d->firstsheet > 0) if (d->firstsheet > 0)
writer.writeAttribute("firstSheet", QString::number(d->firstsheet + 1)); writer.writeAttribute(QStringLiteral("firstSheet"), QString::number(d->firstsheet + 1));
//Store the activeTab when it isn't the first sheet //Store the activeTab when it isn't the first sheet
if (d->activesheet > 0) if (d->activesheet > 0)
writer.writeAttribute("activeTab", QString::number(d->activesheet)); writer.writeAttribute(QStringLiteral("activeTab"), QString::number(d->activesheet));
writer.writeEndElement();//bookviews writer.writeEndElement();//bookviews
writer.writeStartElement("sheets"); writer.writeStartElement(QStringLiteral("sheets"));
foreach (Worksheet *sheet, d->worksheets) { foreach (Worksheet *sheet, d->worksheets) {
writer.writeEmptyElement("sheet"); writer.writeEmptyElement(QStringLiteral("sheet"));
writer.writeAttribute("name", sheet->name()); writer.writeAttribute(QStringLiteral("name"), sheet->name());
writer.writeAttribute("sheetId", QString::number(sheet->index())); writer.writeAttribute(QStringLiteral("sheetId"), QString::number(sheet->index()));
if (sheet->isHidden()) if (sheet->isHidden())
writer.writeAttribute("state", "hidden"); writer.writeAttribute(QStringLiteral("state"), QStringLiteral("hidden"));
writer.writeAttribute("r:id", QString("rId%1").arg(sheet->index())); writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(sheet->index()));
} }
writer.writeEndElement();//sheets writer.writeEndElement();//sheets
// writer.writeStartElement("definedNames"); // writer.writeStartElement(QStringLiteral("definedNames"));
// writer.writeEndElement();//definedNames // writer.writeEndElement();//definedNames
writer.writeStartElement("calcPr"); writer.writeStartElement(QStringLiteral("calcPr"));
writer.writeAttribute("calcId", "124519"); writer.writeAttribute(QStringLiteral("calcId"), QStringLiteral("124519"));
writer.writeEndElement(); //calcPr writer.writeEndElement(); //calcPr
writer.writeEndElement();//workbook writer.writeEndElement();//workbook

112
src/xlsx/xlsxworksheet.cpp

@ -130,7 +130,7 @@ void WorksheetPrivate::calculateSpans()
if (span_max != INT32_MIN) { if (span_max != INT32_MIN) {
span_min += 1; span_min += 1;
span_max += 1; span_max += 1;
row_spans[span_index] = QString("%1:%2").arg(span_min).arg(span_max); row_spans[span_index] = QStringLiteral("%1:%2").arg(span_min).arg(span_max);
span_max = INT32_MIN; span_max = INT32_MIN;
} }
} }
@ -143,7 +143,7 @@ QString WorksheetPrivate::generateDimensionString()
if (dim_rowmax == INT32_MIN && dim_colmax == INT32_MIN) { if (dim_rowmax == INT32_MIN && dim_colmax == INT32_MIN) {
//If the max dimensions are equal to INT32_MIN, then no dimension have been set //If the max dimensions are equal to INT32_MIN, then no dimension have been set
//and we use the default "A1" //and we use the default "A1"
return "A1"; return QStringLiteral("A1");
} }
if (dim_rowmax == INT32_MIN) { if (dim_rowmax == INT32_MIN) {
@ -154,7 +154,7 @@ QString WorksheetPrivate::generateDimensionString()
} else { } else {
const QString cell_1 = xl_rowcol_to_cell(0, dim_colmin); const QString cell_1 = xl_rowcol_to_cell(0, dim_colmin);
const QString cell_2 = xl_rowcol_to_cell(0, dim_colmax); const QString cell_2 = xl_rowcol_to_cell(0, dim_colmax);
return cell_1 + ":" + cell_2; return cell_1 + QLatin1String(":") + cell_2;
} }
} }
@ -165,7 +165,7 @@ QString WorksheetPrivate::generateDimensionString()
QString cell_1 = xl_rowcol_to_cell(dim_rowmin, dim_colmin); QString cell_1 = xl_rowcol_to_cell(dim_rowmin, dim_colmin);
QString cell_2 = xl_rowcol_to_cell(dim_rowmax, dim_colmax); QString cell_2 = xl_rowcol_to_cell(dim_rowmax, dim_colmax);
return cell_1 + ":" + cell_2; return cell_1 + QLatin1String(":") + cell_2;
} }
/* /*
@ -302,9 +302,9 @@ int Worksheet::write(int row, int column, const QVariant &value, Format *format)
} else if (value.type() == QMetaType::QString) { //string } else if (value.type() == QMetaType::QString) { //string
QString token = value.toString(); QString token = value.toString();
if (token.startsWith("=")) { if (token.startsWith(QLatin1String("="))) {
ret = writeFormula(row, column, token, format); ret = writeFormula(row, column, token, format);
} else if (token.startsWith("{") && token.endsWith("}")) { } else if (token.startsWith(QLatin1String("{")) && token.endsWith(QLatin1String("}"))) {
} else { } else {
ret = writeString(row, column, token, format); ret = writeString(row, column, token, format);
@ -366,7 +366,7 @@ int Worksheet::writeFormula(int row, int column, const QString &content, Format
return -1; return -1;
//Remove the formula '=' sign if exists //Remove the formula '=' sign if exists
if (formula.startsWith("=")) if (formula.startsWith(QLatin1String("=")))
formula.remove(0,1); formula.remove(0,1);
XlsxCellData *data = new XlsxCellData(result, XlsxCellData::Formula, format); XlsxCellData *data = new XlsxCellData(result, XlsxCellData::Formula, format);
@ -411,65 +411,65 @@ void Worksheet::saveToXmlFile(QIODevice *device)
Q_D(Worksheet); Q_D(Worksheet);
XmlStreamWriter writer(device); XmlStreamWriter writer(device);
writer.writeStartDocument("1.0", true); writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement("worksheet"); writer.writeStartElement(QStringLiteral("worksheet"));
writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute("xmlns:r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
//for Excel 2010 //for Excel 2010
// writer.writeAttribute("xmlns:mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); // writer.writeAttribute("xmlns:mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
// writer.writeAttribute("xmlns:x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); // writer.writeAttribute("xmlns:x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
// writer.writeAttribute("mc:Ignorable", "x14ac"); // writer.writeAttribute("mc:Ignorable", "x14ac");
writer.writeStartElement("dimension"); writer.writeStartElement(QStringLiteral("dimension"));
writer.writeAttribute("ref", d->generateDimensionString()); writer.writeAttribute(QStringLiteral("ref"), d->generateDimensionString());
writer.writeEndElement();//dimension writer.writeEndElement();//dimension
writer.writeStartElement("sheetViews"); writer.writeStartElement(QStringLiteral("sheetViews"));
writer.writeStartElement("sheetView"); writer.writeStartElement(QStringLiteral("sheetView"));
if (!d->show_zeros) if (!d->show_zeros)
writer.writeAttribute("showZeros", "0"); writer.writeAttribute(QStringLiteral("showZeros"), QStringLiteral("0"));
if (d->right_to_left) if (d->right_to_left)
writer.writeAttribute("rightToLeft", "1"); writer.writeAttribute(QStringLiteral("rightToLeft"), QStringLiteral("1"));
if (d->selected) if (d->selected)
writer.writeAttribute("tabSelected", "1"); writer.writeAttribute(QStringLiteral("tabSelected"), QStringLiteral("1"));
writer.writeAttribute("workbookViewId", "0"); writer.writeAttribute(QStringLiteral("workbookViewId"), QStringLiteral("0"));
writer.writeEndElement();//sheetView writer.writeEndElement();//sheetView
writer.writeEndElement();//sheetViews writer.writeEndElement();//sheetViews
writer.writeStartElement("sheetFormatPr"); writer.writeStartElement(QStringLiteral("sheetFormatPr"));
writer.writeAttribute("defaultRowHeight", QString::number(d->default_row_height)); writer.writeAttribute(QStringLiteral("defaultRowHeight"), QString::number(d->default_row_height));
if (d->default_row_height != 15) if (d->default_row_height != 15)
writer.writeAttribute("customHeight", "1"); writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1"));
if (d->default_row_zeroed) if (d->default_row_zeroed)
writer.writeAttribute("zeroHeight", "1"); writer.writeAttribute(QStringLiteral("zeroHeight"), QStringLiteral("1"));
if (d->outline_row_level) if (d->outline_row_level)
writer.writeAttribute("outlineLevelRow", QString::number(d->outline_row_level)); writer.writeAttribute(QStringLiteral("outlineLevelRow"), QString::number(d->outline_row_level));
if (d->outline_col_level) if (d->outline_col_level)
writer.writeAttribute("outlineLevelCol", QString::number(d->outline_col_level)); writer.writeAttribute(QStringLiteral("outlineLevelCol"), QString::number(d->outline_col_level));
//for Excel 2010 //for Excel 2010
// writer.writeAttribute("x14ac:dyDescent", "0.25"); // writer.writeAttribute("x14ac:dyDescent", "0.25");
writer.writeEndElement();//sheetFormatPr writer.writeEndElement();//sheetFormatPr
if (!d->colsInfo.isEmpty()) { if (!d->colsInfo.isEmpty()) {
writer.writeStartElement("cols"); writer.writeStartElement(QStringLiteral("cols"));
foreach (XlsxColumnInfo *col_info, d->colsInfo) { foreach (XlsxColumnInfo *col_info, d->colsInfo) {
writer.writeStartElement("col"); writer.writeStartElement(QStringLiteral("col"));
writer.writeAttribute("min", QString::number(col_info->column_min)); writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->column_min));
writer.writeAttribute("max", QString::number(col_info->column_max)); writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->column_max));
writer.writeAttribute("width", QString::number(col_info->width, 'g', 15)); writer.writeAttribute(QStringLiteral("width"), QString::number(col_info->width, 'g', 15));
if (col_info->format) if (col_info->format)
writer.writeAttribute("style", QString::number(col_info->format->xfIndex())); writer.writeAttribute(QStringLiteral("style"), QString::number(col_info->format->xfIndex()));
if (col_info->hidden) if (col_info->hidden)
writer.writeAttribute("hidden", "1"); writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1"));
if (col_info->width) if (col_info->width)
writer.writeAttribute("customWidth", "1"); writer.writeAttribute(QStringLiteral("customWidth"), QStringLiteral("1"));
writer.writeEndElement();//col writer.writeEndElement();//col
} }
writer.writeEndElement();//cols writer.writeEndElement();//cols
} }
writer.writeStartElement("sheetData"); writer.writeStartElement(QStringLiteral("sheetData"));
if (d->dim_rowmax == INT32_MIN) { if (d->dim_rowmax == INT32_MIN) {
//If the max dimensions are equal to INT32_MIN, then there is no data to write //If the max dimensions are equal to INT32_MIN, then there is no data to write
} else { } else {
@ -496,24 +496,24 @@ void WorksheetPrivate::writeSheetData(XmlStreamWriter &writer)
span = row_spans[span_index]; span = row_spans[span_index];
if (cellTable.contains(row_num)) { if (cellTable.contains(row_num)) {
writer.writeStartElement("row"); writer.writeStartElement(QStringLiteral("row"));
writer.writeAttribute("r", QString::number(row_num + 1)); writer.writeAttribute(QStringLiteral("r"), QString::number(row_num + 1));
if (!span.isEmpty()) if (!span.isEmpty())
writer.writeAttribute("spans", span); writer.writeAttribute(QStringLiteral("spans"), span);
if (rowsInfo.contains(row_num)) { if (rowsInfo.contains(row_num)) {
XlsxRowInfo *rowInfo = rowsInfo[row_num]; XlsxRowInfo *rowInfo = rowsInfo[row_num];
if (rowInfo->format) { if (rowInfo->format) {
writer.writeAttribute("s", QString::number(rowInfo->format->xfIndex())); writer.writeAttribute(QStringLiteral("s"), QString::number(rowInfo->format->xfIndex()));
writer.writeAttribute("customFormat", "1"); writer.writeAttribute(QStringLiteral("customFormat"), QStringLiteral("1"));
} }
if (rowInfo->height != 15) { if (rowInfo->height != 15) {
writer.writeAttribute("ht", QString::number(rowInfo->height)); writer.writeAttribute(QStringLiteral("ht"), QString::number(rowInfo->height));
writer.writeAttribute("customHeight", "1"); writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1"));
} }
if (rowInfo->hidden) if (rowInfo->hidden)
writer.writeAttribute("hidden", "1"); writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1"));
} }
for (int col_num = dim_colmin; col_num <= dim_colmax; col_num++) { for (int col_num = dim_colmin; col_num <= dim_colmax; col_num++) {
@ -535,36 +535,36 @@ void WorksheetPrivate::writeCellData(XmlStreamWriter &writer, int row, int col,
//This is the innermost loop so efficiency is important. //This is the innermost loop so efficiency is important.
QString cell_range = xl_rowcol_to_cell_fast(row, col); QString cell_range = xl_rowcol_to_cell_fast(row, col);
writer.writeStartElement("c"); writer.writeStartElement(QStringLiteral("c"));
writer.writeAttribute("r", cell_range); writer.writeAttribute(QStringLiteral("r"), cell_range);
//Style used by the cell, row or col //Style used by the cell, row or col
if (cell->format) if (cell->format)
writer.writeAttribute("s", QString::number(cell->format->xfIndex())); writer.writeAttribute(QStringLiteral("s"), QString::number(cell->format->xfIndex()));
else if (rowsInfo.contains(row) && rowsInfo[row]->format) else if (rowsInfo.contains(row) && rowsInfo[row]->format)
writer.writeAttribute("s", QString::number(rowsInfo[row]->format->xfIndex())); writer.writeAttribute(QStringLiteral("s"), QString::number(rowsInfo[row]->format->xfIndex()));
else if (colsInfoHelper.contains(col) && colsInfoHelper[col]->format) else if (colsInfoHelper.contains(col) && colsInfoHelper[col]->format)
writer.writeAttribute("s", QString::number(colsInfoHelper[col]->format->xfIndex())); writer.writeAttribute(QStringLiteral("s"), QString::number(colsInfoHelper[col]->format->xfIndex()));
if (cell->dataType == XlsxCellData::String) { if (cell->dataType == XlsxCellData::String) {
//cell->data: Index of the string in sharedStringTable //cell->data: Index of the string in sharedStringTable
writer.writeAttribute("t", "s"); writer.writeAttribute(QStringLiteral("t"), QStringLiteral("s"));
writer.writeTextElement("v", cell->value.toString()); writer.writeTextElement(QStringLiteral("v"), cell->value.toString());
} else if (cell->dataType == XlsxCellData::Number){ } else if (cell->dataType == XlsxCellData::Number){
double value = cell->value.toDouble(); double value = cell->value.toDouble();
writer.writeTextElement("v", QString::number(value, 'g', 15)); writer.writeTextElement(QStringLiteral("v"), QString::number(value, 'g', 15));
} else if (cell->dataType == XlsxCellData::Formula) { } else if (cell->dataType == XlsxCellData::Formula) {
bool ok = true; bool ok = true;
cell->formula.toDouble(&ok); cell->formula.toDouble(&ok);
if (!ok) //is string if (!ok) //is string
writer.writeAttribute("t", "str"); writer.writeAttribute(QStringLiteral("t"), QStringLiteral("str"));
writer.writeTextElement("f", cell->formula); writer.writeTextElement(QStringLiteral("f"), cell->formula);
writer.writeTextElement("v", cell->value.toString()); writer.writeTextElement(QStringLiteral("v"), cell->value.toString());
} else if (cell->dataType == XlsxCellData::ArrayFormula) { } else if (cell->dataType == XlsxCellData::ArrayFormula) {
} else if (cell->dataType == XlsxCellData::Boolean) { } else if (cell->dataType == XlsxCellData::Boolean) {
writer.writeAttribute("t", "b"); writer.writeAttribute(QStringLiteral("t"), QStringLiteral("b"));
writer.writeTextElement("v", cell->value.toBool() ? "1" : "0"); writer.writeTextElement(QStringLiteral("v"), cell->value.toBool() ? QStringLiteral("1") : QStringLiteral("0"));
} else if (cell->dataType == XlsxCellData::Blank) { } else if (cell->dataType == XlsxCellData::Blank) {
//Ok, empty here. //Ok, empty here.
} else if (cell->dataType == XlsxCellData::DateTime) { } else if (cell->dataType == XlsxCellData::DateTime) {
@ -576,7 +576,7 @@ void WorksheetPrivate::writeCellData(XmlStreamWriter &writer, int row, int col,
//Account for Excel erroneously treating 1900 as a leap year. //Account for Excel erroneously treating 1900 as a leap year.
if (!workbook->isDate1904() && excel_time > 59) if (!workbook->isDate1904() && excel_time > 59)
excel_time += 1; excel_time += 1;
writer.writeTextElement("v", QString::number(excel_time, 'g', 15)); writer.writeTextElement(QStringLiteral("v"), QString::number(excel_time, 'g', 15));
} }
writer.writeEndElement(); //c writer.writeEndElement(); //c
} }

Loading…
Cancel
Save