You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
4.6 KiB
101 lines
4.6 KiB
12 years ago
|
/****************************************************************************
|
||
|
** Copyright (c) 2013 Debao Zhang <hello@debao.me>
|
||
|
** 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.
|
||
|
**
|
||
|
****************************************************************************/
|
||
12 years ago
|
#include "xlsxdocpropsapp_p.h"
|
||
12 years ago
|
#include "xlsxxmlwriter_p.h"
|
||
12 years ago
|
|
||
|
#include <QDir>
|
||
|
#include <QFile>
|
||
|
#include <QDateTime>
|
||
12 years ago
|
#include <QVariant>
|
||
12 years ago
|
namespace QXlsx {
|
||
|
|
||
12 years ago
|
DocPropsApp::DocPropsApp(QObject *parent) :
|
||
12 years ago
|
QObject(parent)
|
||
|
{
|
||
|
}
|
||
|
|
||
12 years ago
|
void DocPropsApp::addPartTitle(const QString &title)
|
||
12 years ago
|
{
|
||
|
m_titlesOfPartsList.append(title);
|
||
|
}
|
||
|
|
||
12 years ago
|
void DocPropsApp::addHeadingPair(const QString &name, int value)
|
||
12 years ago
|
{
|
||
|
m_headingPairsList.append(qMakePair(name, value));
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void DocPropsApp::saveToXmlFile(QIODevice *device)
|
||
12 years ago
|
{
|
||
|
XmlStreamWriter writer(device);
|
||
|
|
||
12 years ago
|
writer.writeStartDocument(QStringLiteral("1.0"), true);
|
||
|
writer.writeStartElement(QStringLiteral("Properties"));
|
||
|
writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
|
||
|
writer.writeAttribute(QStringLiteral("xmlns:vt"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"));
|
||
|
writer.writeTextElement(QStringLiteral("Application"), QStringLiteral("Microsoft Excel"));
|
||
|
writer.writeTextElement(QStringLiteral("DocSecurity"), QStringLiteral("0"));
|
||
|
writer.writeTextElement(QStringLiteral("ScaleCrop"), QStringLiteral("false"));
|
||
|
|
||
|
writer.writeStartElement(QStringLiteral("HeadingPairs"));
|
||
|
writer.writeStartElement(QStringLiteral("vt:vector"));
|
||
|
writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size()*2));
|
||
|
writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("variant"));
|
||
12 years ago
|
typedef QPair<QString,int> PairType; //Make foreach happy
|
||
|
foreach (PairType pair, m_headingPairsList) {
|
||
12 years ago
|
writer.writeStartElement(QStringLiteral("vt:variant"));
|
||
|
writer.writeTextElement(QStringLiteral("vt:lpstr"), pair.first);
|
||
12 years ago
|
writer.writeEndElement(); //vt:variant
|
||
12 years ago
|
writer.writeStartElement(QStringLiteral("vt:variant"));
|
||
|
writer.writeTextElement(QStringLiteral("vt:i4"), QString::number(pair.second));
|
||
12 years ago
|
writer.writeEndElement(); //vt:variant
|
||
|
}
|
||
|
writer.writeEndElement();//vt:vector
|
||
|
writer.writeEndElement();//HeadingPairs
|
||
|
|
||
12 years ago
|
writer.writeStartElement(QStringLiteral("TitlesOfParts"));
|
||
|
writer.writeStartElement(QStringLiteral("vt:vector"));
|
||
|
writer.writeAttribute(QStringLiteral("size"), QString::number(m_titlesOfPartsList.size()));
|
||
|
writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("lpstr"));
|
||
12 years ago
|
foreach (QString title, m_titlesOfPartsList)
|
||
12 years ago
|
writer.writeTextElement(QStringLiteral("vt:lpstr"), title);
|
||
12 years ago
|
writer.writeEndElement();//vt:vector
|
||
|
writer.writeEndElement();//TitlesOfParts
|
||
|
|
||
12 years ago
|
if (property("manager").isValid())
|
||
|
writer.writeTextElement(QStringLiteral("Manager"), property("manager").toString());
|
||
|
//Not like "manager", "company" always exists for Excel generated file.
|
||
|
writer.writeTextElement(QStringLiteral("Company"), property("company").isValid() ? property("company").toString() : QString());
|
||
12 years ago
|
writer.writeTextElement(QStringLiteral("LinksUpToDate"), QStringLiteral("false"));
|
||
|
writer.writeTextElement(QStringLiteral("SharedDoc"), QStringLiteral("false"));
|
||
|
writer.writeTextElement(QStringLiteral("HyperlinksChanged"), QStringLiteral("false"));
|
||
|
writer.writeTextElement(QStringLiteral("AppVersion"), QStringLiteral("12.0000"));
|
||
12 years ago
|
|
||
12 years ago
|
writer.writeEndElement(); //Properties
|
||
|
writer.writeEndDocument();
|
||
|
}
|
||
|
|
||
|
} //namespace
|