diff --git a/src/xlsx/qtxlsx.pri b/src/xlsx/qtxlsx.pri index 8a01554..c013dfc 100755 --- a/src/xlsx/qtxlsx.pri +++ b/src/xlsx/qtxlsx.pri @@ -4,7 +4,8 @@ DEPENDPATH += $$PWD QT += core gui gui-private !build_xlsx_lib:DEFINES += XLSX_NO_LIB -HEADERS += $$PWD/xlsxdocprops_p.h \ +HEADERS += $$PWD/xlsxdocpropscore_p.h \ + $$PWD/xlsxdocpropsapp_p.h \ $$PWD/xlsxrelationships_p.h \ $$PWD/xlsxutility_p.h \ $$PWD/xlsxsharedstrings_p.h \ @@ -22,7 +23,8 @@ HEADERS += $$PWD/xlsxdocprops_p.h \ $$PWD/xlsxformat_p.h \ $$PWD/xlsxglobal.h -SOURCES += $$PWD/xlsxdocprops.cpp \ +SOURCES += $$PWD/xlsxdocpropscore.cpp \ + $$PWD/xlsxdocpropsapp.cpp \ $$PWD/xlsxrelationships.cpp \ $$PWD/xlsxutility.cpp \ $$PWD/xlsxsharedstrings.cpp \ diff --git a/src/xlsx/xlsxdocprops.cpp b/src/xlsx/xlsxdocpropsapp.cpp similarity index 61% rename from src/xlsx/xlsxdocprops.cpp rename to src/xlsx/xlsxdocpropsapp.cpp index 0db4e55..052e255 100755 --- a/src/xlsx/xlsxdocprops.cpp +++ b/src/xlsx/xlsxdocpropsapp.cpp @@ -22,7 +22,7 @@ ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ** ****************************************************************************/ -#include "xlsxdocprops_p.h" +#include "xlsxdocpropsapp_p.h" #include "xlsxxmlwriter_p.h" #include @@ -31,23 +31,23 @@ #include namespace QXlsx { -DocProps::DocProps(QObject *parent) : +DocPropsApp::DocPropsApp(QObject *parent) : QObject(parent) { } -void DocProps::addPartTitle(const QString &title) +void DocPropsApp::addPartTitle(const QString &title) { m_titlesOfPartsList.append(title); } -void DocProps::addHeadingPair(const QString &name, int value) +void DocPropsApp::addHeadingPair(const QString &name, int value) { m_headingPairsList.append(qMakePair(name, value)); } -void DocProps::saveToXmlFile_App(QIODevice *device) +void DocPropsApp::saveToXmlFile(QIODevice *device) { XmlStreamWriter writer(device); @@ -97,45 +97,4 @@ void DocProps::saveToXmlFile_App(QIODevice *device) writer.writeEndDocument(); } -void DocProps::saveToXmlFile_Core(QIODevice *device) -{ - XmlStreamWriter writer(device); - - writer.writeStartDocument(QStringLiteral("1.0"), true); - writer.writeStartElement(QStringLiteral("cp:coreProperties")); - writer.writeAttribute(QStringLiteral("xmlns:cp"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")); - writer.writeAttribute(QStringLiteral("xmlns:dc"), QStringLiteral("http://purl.org/dc/elements/1.1/")); - writer.writeAttribute(QStringLiteral("xmlns:dcterms"), QStringLiteral("http://purl.org/dc/terms/")); - writer.writeAttribute(QStringLiteral("xmlns:dcmitype"), QStringLiteral("http://purl.org/dc/dcmitype/")); - writer.writeAttribute(QStringLiteral("xmlns:xsi"), QStringLiteral("http://www.w3.org/2001/XMLSchema-instance")); - if (property("title").isValid()) - writer.writeTextElement(QStringLiteral("dc:title"), property("title").toString()); - if (property("subject").isValid()) - writer.writeTextElement(QStringLiteral("dc:subject"), property("subject").toString()); - writer.writeTextElement(QStringLiteral("dc:creator"), property("creator").isValid() ? property("creator").toString() : QStringLiteral("Qt Xlsx Library")); - - if (property("keywords").isValid()) - writer.writeTextElement(QStringLiteral("cp:keywords"), property("keywords").toString()); - if (property("description").isValid()) - writer.writeTextElement(QStringLiteral("dc:description"), property("description").toString()); - writer.writeTextElement(QStringLiteral("cp:lastModifiedBy"), property("creator").isValid() ? property("creator").toString() : QStringLiteral("Qt Xlsx Library")); - - writer.writeStartElement(QStringLiteral("dcterms:created")); - writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF")); - writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); - writer.writeEndElement();//dcterms:created - - writer.writeStartElement(QStringLiteral("dcterms:modified")); - writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF")); - writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); - writer.writeEndElement();//dcterms:created - - if (property("category").isValid()) - writer.writeTextElement(QStringLiteral("cp:category"), property("category").toString()); - if (property("status").isValid()) - writer.writeTextElement(QStringLiteral("cp:contentStatus"), property("status").toString()); - writer.writeEndElement(); //cp:coreProperties - writer.writeEndDocument(); -} - } //namespace diff --git a/src/xlsx/xlsxdocprops_p.h b/src/xlsx/xlsxdocpropsapp_p.h similarity index 86% rename from src/xlsx/xlsxdocprops_p.h rename to src/xlsx/xlsxdocpropsapp_p.h index 4cecb8a..ac75875 100755 --- a/src/xlsx/xlsxdocprops_p.h +++ b/src/xlsx/xlsxdocpropsapp_p.h @@ -22,8 +22,8 @@ ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ** ****************************************************************************/ -#ifndef XLSXDOCPROPS_H -#define XLSXDOCPROPS_H +#ifndef XLSXDOCPROPSAPP_H +#define XLSXDOCPROPSAPP_H #include "xlsxglobal.h" #include @@ -35,19 +35,18 @@ class QIODevice; namespace QXlsx { -class XLSX_AUTOTEST_EXPORT DocProps : public QObject +class XLSX_AUTOTEST_EXPORT DocPropsApp : public QObject { Q_OBJECT public: - explicit DocProps(QObject *parent = 0); + explicit DocPropsApp(QObject *parent = 0); signals: public slots: void addPartTitle(const QString &title); void addHeadingPair(const QString &name, int value); - void saveToXmlFile_App(QIODevice *device); - void saveToXmlFile_Core(QIODevice *device); + void saveToXmlFile(QIODevice *device); private: QStringList m_titlesOfPartsList; @@ -55,4 +54,4 @@ private: }; } -#endif // XLSXDOCPROPS_H +#endif // XLSXDOCPROPSAPP_H diff --git a/src/xlsx/xlsxdocpropscore.cpp b/src/xlsx/xlsxdocpropscore.cpp new file mode 100644 index 0000000..3e6f633 --- /dev/null +++ b/src/xlsx/xlsxdocpropscore.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** Copyright (c) 2013 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxdocpropscore_p.h" +#include "xlsxxmlwriter_p.h" + +#include +#include +#include +#include +namespace QXlsx { + +DocPropsCore::DocPropsCore(QObject *parent) : + QObject(parent) +{ +} + +void DocPropsCore::saveToXmlFile(QIODevice *device) +{ + XmlStreamWriter writer(device); + + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("cp:coreProperties")); + writer.writeAttribute(QStringLiteral("xmlns:cp"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")); + writer.writeAttribute(QStringLiteral("xmlns:dc"), QStringLiteral("http://purl.org/dc/elements/1.1/")); + writer.writeAttribute(QStringLiteral("xmlns:dcterms"), QStringLiteral("http://purl.org/dc/terms/")); + writer.writeAttribute(QStringLiteral("xmlns:dcmitype"), QStringLiteral("http://purl.org/dc/dcmitype/")); + writer.writeAttribute(QStringLiteral("xmlns:xsi"), QStringLiteral("http://www.w3.org/2001/XMLSchema-instance")); + if (property("title").isValid()) + writer.writeTextElement(QStringLiteral("dc:title"), property("title").toString()); + if (property("subject").isValid()) + writer.writeTextElement(QStringLiteral("dc:subject"), property("subject").toString()); + writer.writeTextElement(QStringLiteral("dc:creator"), property("creator").isValid() ? property("creator").toString() : QStringLiteral("Qt Xlsx Library")); + + if (property("keywords").isValid()) + writer.writeTextElement(QStringLiteral("cp:keywords"), property("keywords").toString()); + if (property("description").isValid()) + writer.writeTextElement(QStringLiteral("dc:description"), property("description").toString()); + writer.writeTextElement(QStringLiteral("cp:lastModifiedBy"), property("creator").isValid() ? property("creator").toString() : QStringLiteral("Qt Xlsx Library")); + + writer.writeStartElement(QStringLiteral("dcterms:created")); + writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF")); + writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); + writer.writeEndElement();//dcterms:created + + writer.writeStartElement(QStringLiteral("dcterms:modified")); + writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF")); + writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); + writer.writeEndElement();//dcterms:created + + if (property("category").isValid()) + writer.writeTextElement(QStringLiteral("cp:category"), property("category").toString()); + if (property("status").isValid()) + writer.writeTextElement(QStringLiteral("cp:contentStatus"), property("status").toString()); + writer.writeEndElement(); //cp:coreProperties + writer.writeEndDocument(); +} + +} //namespace diff --git a/src/xlsx/xlsxdocpropscore_p.h b/src/xlsx/xlsxdocpropscore_p.h new file mode 100644 index 0000000..63749e7 --- /dev/null +++ b/src/xlsx/xlsxdocpropscore_p.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** Copyright (c) 2013 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXDOCPROPSCORE_H +#define XLSXDOCPROPSCORE_H + +#include "xlsxglobal.h" +#include +#include +#include +#include + +class QIODevice; + +namespace QXlsx { + +class XLSX_AUTOTEST_EXPORT DocPropsCore : public QObject +{ + Q_OBJECT +public: + explicit DocPropsCore(QObject *parent = 0); + + void saveToXmlFile(QIODevice *device); +}; + +} +#endif // XLSXDOCPROPSCORE_H diff --git a/src/xlsx/xlsxpackage.cpp b/src/xlsx/xlsxpackage.cpp index 2ee1ae5..da3a624 100644 --- a/src/xlsx/xlsxpackage.cpp +++ b/src/xlsx/xlsxpackage.cpp @@ -27,7 +27,8 @@ #include "xlsxworksheet.h" #include "xlsxcontenttypes_p.h" #include "xlsxsharedstrings_p.h" -#include "xlsxdocprops_p.h" +#include "xlsxdocpropscore_p.h" +#include "xlsxdocpropsapp_p.h" #include "xlsxtheme_p.h" #include "xlsxstyles_p.h" #include "xlsxrelationships_p.h" @@ -101,7 +102,8 @@ bool Package::createPackage(const QString &packageName) // writeCommentFiles(zipWriter); // writeTableFiles(zipWriter); writeSharedStringsFile(zipWriter); - writeDocPropsFiles(zipWriter); + writeDocPropsAppFile(zipWriter); + writeDocPropsCoreFile(zipWriter); writeContentTypesFiles(zipWriter); m_workbook->styles()->prepareStyles(); writeStylesFiles(zipWriter); @@ -166,9 +168,9 @@ void Package::writeContentTypesFiles(ZipWriter &zipWriter) zipWriter.addFile(QStringLiteral("[Content_Types].xml"), data); } -void Package::writeDocPropsFiles(ZipWriter &zipWriter) +void Package::writeDocPropsAppFile(ZipWriter &zipWriter) { - DocProps props; + DocPropsApp props; foreach (QByteArray name, m_workbook->dynamicPropertyNames()) props.setProperty(name.data(), m_workbook->property(name.data())); @@ -190,17 +192,25 @@ void Package::writeDocPropsFiles(ZipWriter &zipWriter) props.addPartTitle(sheet->name()); } - QByteArray data1; - QBuffer buffer1(&data1); - buffer1.open(QIODevice::WriteOnly); - props.saveToXmlFile_App(&buffer1); - zipWriter.addFile(QStringLiteral("docProps/app.xml"), data1); - - QByteArray data2; - QBuffer buffer2(&data2); - buffer2.open(QIODevice::WriteOnly); - props.saveToXmlFile_Core(&buffer2); - zipWriter.addFile(QStringLiteral("docProps/core.xml"), data2); + QByteArray data; + QBuffer buffer(&data); + buffer.open(QIODevice::WriteOnly); + props.saveToXmlFile(&buffer); + zipWriter.addFile(QStringLiteral("docProps/app.xml"), data); +} + +void Package::writeDocPropsCoreFile(ZipWriter &zipWriter) +{ + DocPropsCore props; + + foreach (QByteArray name, m_workbook->dynamicPropertyNames()) + props.setProperty(name.data(), m_workbook->property(name.data())); + + QByteArray data; + QBuffer buffer(&data); + buffer.open(QIODevice::WriteOnly); + props.saveToXmlFile(&buffer); + zipWriter.addFile(QStringLiteral("docProps/core.xml"), data); } void Package::writeSharedStringsFile(ZipWriter &zipWriter) diff --git a/src/xlsx/xlsxpackage_p.h b/src/xlsx/xlsxpackage_p.h index e7685e8..927471d 100644 --- a/src/xlsx/xlsxpackage_p.h +++ b/src/xlsx/xlsxpackage_p.h @@ -49,7 +49,8 @@ private: // void writeCommentFiles(ZipWriter &zipWriter); // void writeTableFiles(ZipWriter &zipWriter); void writeSharedStringsFile(ZipWriter &zipWriter); - void writeDocPropsFiles(ZipWriter &zipWriter); + void writeDocPropsAppFile(ZipWriter &zipWriter); + void writeDocPropsCoreFile(ZipWriter &zipWriter); void writeContentTypesFiles(ZipWriter &zipWriter); void writeStylesFiles(ZipWriter &zipWriter); void writeThemeFile(ZipWriter &zipWriter);