1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00

Add and apply clang-format

This project has no standard on coding style,
some files use tab, others space, and new
Merge Requests usually break the current formatting
with this clang-format we can easy this.
This commit is contained in:
Daniel Nicoletti 2023-09-04 00:46:33 -03:00
parent 499901003f
commit db608768a3
123 changed files with 7953 additions and 8230 deletions

93
.clang-format Normal file
View File

@ -0,0 +1,93 @@
# .clang-format for Cutelyst projects 2023-04-18
# Tries to be close to Qt coding style
# but meh for ASql lambdas which LambdaBodyIndentation ins't enough
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: 'false'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'false'
AllowShortEnumsOnASingleLine: 'true'
AlignEscapedNewlines: DontAlign
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: 'true'
AfterClass: 'true'
AfterEnum: 'false'
AfterFunction: true
SplitEmptyFunction: 'true'
SplitEmptyRecord: 'true'
SplitEmptyNamespace: 'true'
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: 'true'
CompactNamespaces: 'false'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
ColumnLimit: 100
Cpp11BracedListStyle: 'true'
FixNamespaceComments: 'true'
ForEachMacros:
- forever # avoids { wrapped to next line
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<Q.*'
Priority: 200
IncludeBlocks: Regroup
IndentAccessModifiers: 'false'
IndentCaseLabels: 'false'
IndentPPDirectives: AfterHash
IndentWidth: '4'
IndentWrappedFunctionNames: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'true'
Language: Cpp
LambdaBodyIndentation: OuterScope
NamespaceIndentation: None
PointerAlignment: Right
ReflowComments: 'true'
SortIncludes: 'true'
SortUsingDeclarations: 'false'
SpaceAfterCStyleCast: 'true'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'false'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
WhitespaceSensitiveMacros:
- C_ATTR
UseTab: Never
...

View File

@ -1,19 +1,19 @@
// main.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <iostream>
#include <QCoreApplication>
#include <QDebug>
#include <QVariant>
#include <QVector>
#include <QtCore>
#include <QtGlobal>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
@ -30,4 +30,3 @@ int main(int argc, char *argv[])
return 0;
}

View File

@ -1,20 +1,20 @@
// test.cpp
#include <QtGlobal>
#include <iostream>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <QDir>
#include <iostream>
#include <QVariant>
#include <QVector>
#include <QtCore>
#include <QtGlobal>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
@ -99,8 +99,7 @@ int test2( QVector<QVariant> params )
qDebug() << "\n\ndoc2\n";
Document doc2("datetime.xlsx");
if ( !doc2.load() )
{
if (!doc2.load()) {
qWarning() << "failed to load datetime.xlsx";
return (-1);
}
@ -141,8 +140,7 @@ int test2( QVector<QVariant> params )
qDebug() << "\n\ndoc3\n";
Document doc3("datetime2.xlsx");
if ( !doc3.load() )
{
if (!doc3.load()) {
qWarning() << "failed to load datetime2.xlsx";
return (-1);
}
@ -176,4 +174,3 @@ int test2( QVector<QVariant> params )
return 0;
}

View File

@ -2,36 +2,30 @@
#ifndef DYNARRAY2D_H
#define DYNARRAY2D_H
// Code from https://www.qtcentre.org/threads/31440-two-dimensional-array-size-determined-dynamically
// Some code is fixed by j2doll
// Code from
// https://www.qtcentre.org/threads/31440-two-dimensional-array-size-determined-dynamically Some
// code is fixed by j2doll
template <typename T> class DynArray2D
template <typename T>
class DynArray2D
{
public:
DynArray2D(int n, int m)
{
_n = n;
_array = new T *[n];
for(int i = 0; i < n; i++)
{
for (int i = 0; i < n; i++) {
_array[i] = new T[m];
}
}
void setValue(int n, int m, T v)
{
_array[n][m] = v;
}
void setValue(int n, int m, T v) { _array[n][m] = v; }
T getValue(int n, int m)
{
return _array[n][m];
}
T getValue(int n, int m) { return _array[n][m]; }
~DynArray2D()
{
for (int i = 0 ; i < _n ; i++)
{
for (int i = 0; i < _n; i++) {
delete[] _array[i];
}
delete[] _array;
@ -42,5 +36,4 @@ protected:
int _n;
};
#endif // DYNARRAY2D_H

View File

@ -6,11 +6,10 @@
#include "XlsxTableModel.h"
#include <QDebug>
#include <QVariant>
#include <sstream>
#include <QDebug>
#include <QVariant>
XlsxTableModel::XlsxTableModel(const QList<QString> &colTitle, QList<VLIST> data, QObject *parent)
: QAbstractTableModel(parent)
@ -22,8 +21,7 @@ XlsxTableModel::XlsxTableModel(const QList<QString> &colTitle, QList<VLIST> data
// [2] set data
for (int dc = 0; dc < data.size() ; dc++ )
{
for (int dc = 0; dc < data.size(); dc++) {
VLIST vList = data.at(dc);
m_the_data.append(vList);
}
@ -73,7 +71,6 @@ void XlsxTableModel::testData()
list4.append(QVariant(40));
list4.append(QVariant(400.0));
m_the_data.append(list4);
}
int XlsxTableModel::rowCount(const QModelIndex &parent) const
@ -95,10 +92,9 @@ QVariant XlsxTableModel::data(const QModelIndex& index, int role) const
int row = index.row();
// check boudaries
if ( col < 0 || columnCount() <= col ||
row < 0 || rowCount() <= row )
{
qDebug() << "[Warning]" << " col=" << col << ", row=" << row;
if (col < 0 || columnCount() <= col || row < 0 || rowCount() <= row) {
qDebug() << "[Warning]"
<< " col=" << col << ", row=" << row;
return QVariant();
}
@ -107,31 +103,27 @@ QVariant XlsxTableModel::data(const QModelIndex& index, int role) const
QVariant ret;
int cmpRole;
for (int ic = 0; ic < m_the_data.size() ; ic++)
{
if ( row == ic )
{
for (int ic = 0; ic < m_the_data.size(); ic++) {
if (row == ic) {
QList<QVariant> vList = m_the_data.at(ic);
for (int jc = 0; jc < vList.size() ; jc++ )
{
for (int jc = 0; jc < vList.size(); jc++) {
int plusOneRole = (int) (Qt::UserRole);
plusOneRole = plusOneRole + 1;
cmpRole = plusOneRole + jc;
if ( role == cmpRole )
{
if (role == cmpRole) {
QVariant var = vList.at(jc);
if ( ! var.isValid() ) var.setValue( QString("") ) ;
if ( var.isNull() ) var.setValue( QString("") ) ;
if (!var.isValid())
var.setValue(QString(""));
if (var.isNull())
var.setValue(QString(""));
ret = var;
}
}
}
}
qDebug()
<< "data: "
<< " col=" << col << ", row=" << row
<< ", role=" << role << ", cmpRole=" << cmpRole
qDebug() << "data: "
<< " col=" << col << ", row=" << row << ", role=" << role << ", cmpRole=" << cmpRole
<< ", value=" << ret.toString();
return ret;
@ -141,8 +133,7 @@ QHash<int, QByteArray> XlsxTableModel::roleNames() const
{
QHash<int, QByteArray> roles;
for ( int ic = 0 ; ic < m_roleCount ; ic++)
{
for (int ic = 0; ic < m_roleCount; ic++) {
QString strRole = m_colNames.at(ic);
int roleNo = (Qt::UserRole + 1) + ic;
roles.insert(roleNo, strRole.toLatin1());
@ -157,16 +148,12 @@ QStringList XlsxTableModel::customRoleNames()
QMap<int, QString> res;
QHashIterator<int, QByteArray> i(roleNames());
while ( i.hasNext() )
{
while (i.hasNext()) {
i.next();
if ( i.key() > Qt::UserRole )
{
if (i.key() > Qt::UserRole) {
res[i.key()] = i.value();
}
}
return res.values();
}

View File

@ -7,19 +7,19 @@
#ifndef XLSX_MODEL_H
#define XLSX_MODEL_H
#include <QtGlobal>
#include <cstdlib>
#include <string>
#include <vector>
#include <QAbstractTableModel>
#include <QList>
#include <QMap>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QList>
#include <QVector>
#include <QMap>
#include <QVariant>
#include <QAbstractTableModel>
#include <string>
#include <vector>
#include <cstdlib>
#include <QVector>
#include <QtGlobal>
typedef QList<QVariant> VLIST;
@ -29,7 +29,8 @@ class XlsxTableModel : public QAbstractTableModel
// method that is called by QML script
Q_PROPERTY(QStringList customRoleNames READ customRoleNames CONSTANT)
public: QStringList customRoleNames();
public:
QStringList customRoleNames();
public: // constrcutor
XlsxTableModel(const QList<QString> &colTitle, QList<VLIST> data, QObject *parent = NULL);
@ -47,7 +48,6 @@ protected:
QList<VLIST> m_the_data; // table cell data
QList<QString> m_colNames; // column name
quint32 m_roleCount; // role count (same as column count)
};
#endif

View File

@ -4,32 +4,30 @@
// main.cpp
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QUrl>
#include <QList>
#include <QVariant>
#include <QDebug>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
#include <cstdio>
#include <iostream>
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
#include <QDebug>
#include <QGuiApplication>
#include <QList>
#include <QObject>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QString>
#include <QUrl>
#include <QVariant>
#include <QtGlobal>
using namespace QXlsx;
#include "XlsxTableModel.h"
#include "DynArray2D.h"
#include "XlsxTableModel.h"
std::string convertFromNumberToExcelColumn(int n);
@ -43,8 +41,7 @@ int main(int argc, char *argv[])
QQmlContext *ctxt = engine.rootContext();
QXlsx::Document xlsx(":/test.xlsx"); // load xlsx
if (!xlsx.load())
{
if (!xlsx.load()) {
qDebug() << "[ERROR] Failed to load xlsx";
return (-1);
}
@ -52,8 +49,7 @@ int main(int argc, char *argv[])
QList<QString> colTitle; // list of column title
QVector<CellLocation> vcl; // vector of cell(s) location
Worksheet *wsheet = (Worksheet *) xlsx.workbook()->activeSheet();
if ( NULL == wsheet )
{
if (NULL == wsheet) {
qDebug() << "[ERROR] Failed to get active sheet";
return (-2);
}
@ -65,8 +61,7 @@ int main(int argc, char *argv[])
Q_ASSERT((-1) != rowMax); // To CHECK
Q_ASSERT((-1) != colMax);
for (int ic = 0 ; ic < colMax ; ic++)
{
for (int ic = 0; ic < colMax; ic++) {
std::string strCol = convertFromNumberToExcelColumn(ic + 1);
QString colName = QString::fromStdString(strCol);
colTitle.append(colName);
@ -76,8 +71,7 @@ int main(int argc, char *argv[])
DynArray2D<std::string> dynIntArray(colMax, rowMax);
for ( int icl = 0; icl < vcl.size(); ++icl )
{
for (int icl = 0; icl < vcl.size(); ++icl) {
CellLocation cl = vcl.at(icl); // cell location
// NOTICE: First cell of tableWidget is 0.
@ -96,11 +90,9 @@ int main(int argc, char *argv[])
}
QList<VLIST> xlsxData;
for (int ir = 0; ir < rowMax; ir++ )
{
for (int ir = 0; ir < rowMax; ir++) {
VLIST vl;
for (int ic = 0; ic < colMax; ic++)
{
for (int ic = 0; ic < colMax; ic++) {
std::string value = dynIntArray.getValue(ic, ir);
vl.append(QString::fromStdString(value));
}
@ -112,8 +104,7 @@ int main(int argc, char *argv[])
ctxt->setContextProperty("xlsxModel", &xlsxTableModel);
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // load QML
if ( engine.rootObjects().isEmpty() )
{
if (engine.rootObjects().isEmpty()) {
qDebug() << "Failed to load qml";
return (-1);
}
@ -132,18 +123,15 @@ std::string convertFromNumberToExcelColumn(int n)
char str[1000]; // To store result (Excel column name)
int i = 0; // To store current index in str which is result
while ( n > 0 )
{
while (n > 0) {
// Find remainder
int rem = n % 26;
// If remainder is 0, then a 'Z' must be there in output
if ( rem == 0 )
{
if (rem == 0) {
str[i++] = 'Z';
n = (n / 26) - 1;
}
else // If remainder is non-zero
} else // If remainder is non-zero
{
str[i++] = (rem - 1) + 'A';
n = n / 26;

View File

@ -2,21 +2,21 @@
// QXlsx // MIT License // https://github.com/j2doll/QXlsx
//
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVariant>
#include <QDir>
#include <QDebug>
#include <iostream>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QVariant>
#include <QtCore>
#include <QtGlobal>
using namespace std;
// [0] include QXlsx headers
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
@ -30,7 +30,8 @@ int main(int argc, char *argv[])
QXlsx::Document xlsxW;
int row = 1; int col = 1; //
int row = 1;
int col = 1; //
// xlsxW.write("A1", "Hello Qt!"); // write "Hello Qt!" to cell(A,1). it's shared string.
QVariant writeValue = QString("Hello Qt!");
@ -39,9 +40,7 @@ int main(int argc, char *argv[])
if (xlsxW.saveAs("Test.xlsx")) // save the document as 'Test.xlsx'
{
qDebug() << "[debug] success to write xlsx file";
}
else
{
} else {
qDebug() << "[debug][error] failed to write xlsx file";
exit(-1);
}
@ -57,19 +56,15 @@ int main(int argc, char *argv[])
qDebug() << "[debug] success to load xlsx file.";
Cell *cell = xlsxR.cellAt(row, col); // get cell pointer.
if ( cell != NULL )
{
QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...)
if (cell != NULL) {
QVariant var =
cell->readValue(); // read cell value (number(double), QDateTime, QString ...)
qDebug() << "[debug] cell(1,1) is " << var; // Display value. It is 'Hello Qt!'.
}
else
{
} else {
qDebug() << "[debug][error] cell(1,1) is not set.";
exit(-2);
}
}
else
{
} else {
qDebug() << "[debug][error] failed to load xlsx file.";
}

View File

@ -1,19 +1,19 @@
// main.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <iostream>
#include <QCoreApplication>
#include <QDebug>
#include <QVariant>
#include <QVector>
#include <QtCore>
#include <QtGlobal>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
@ -30,4 +30,3 @@ int main(int argc, char *argv[])
return 0;
}

View File

@ -1,24 +1,24 @@
// test.cpp
#include <QtGlobal>
#include <iostream>
#include <QColor>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <QDir>
#include <QColor>
#include <QImage>
#include <QRgb>
#include <QRandomGenerator>
#include <iostream>
#include <QRgb>
#include <QVariant>
#include <QVector>
#include <QtCore>
#include <QtGlobal>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
@ -43,10 +43,5 @@ int test( QVector<QVariant> params )
qDebug() << "[debug] current path : " << QDir::currentPath();
// return test162( params );
return 0;
}

View File

@ -30,8 +30,8 @@
extern "C" {
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdio.h>
#ifdef _WIN32
# include <windows.h>
@ -49,7 +49,8 @@ extern "C" {
* 4 -> magenta
* 5 -> cyan
*/
int colorprintf(int color, const char *format, ...) {
int colorprintf(int color, const char *format, ...)
{
int fcolor = -1, retval = -99;
va_list args;
#ifdef _WIN32

View File

@ -1,19 +1,19 @@
// main.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <iostream>
#include <QCoreApplication>
#include <QDebug>
#include <QVariant>
#include <QVector>
#include <QtCore>
#include <QtGlobal>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
@ -29,4 +29,3 @@ int main(int argc, char *argv[])
return 0;
}

View File

@ -1,28 +1,28 @@
// test.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QDataStream>
#include <QByteArray>
#include <QString>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <QByteArray>
#include <QCoreApplication>
#include <QDataStream>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QVariant>
#include <QVector>
#include <QtCore>
#include <QtGlobal>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
@ -37,14 +37,12 @@ int test( QVector<QVariant> params )
qDebug() << "[debug] current path : " << QDir::currentPath();
QFile fileNames(":/xlsx_files/dir2.txt");
if ( !fileNames.open(QIODevice::ReadOnly | QIODevice::Text) )
{
if (!fileNames.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "[debug] failed to load dir2.txt";
return (-1);
}
while (!fileNames.atEnd())
{
while (!fileNames.atEnd()) {
QByteArray line = fileNames.readLine();
QString strArg(line);
@ -56,19 +54,13 @@ int test( QVector<QVariant> params )
{
using namespace QXlsx;
Document output2(currentFilename);
if ( output2.load() )
{
if ( output2.saveAs( strArg3 ) )
{
if (output2.load()) {
if (output2.saveAs(strArg3)) {
qDebug() << "[debug] xlsx is saved. " << strArg3;
}
else
{
} else {
qCritical() << "[debug] failed to save. " << strArg3;
}
}
else
{
} else {
qCritical() << "[debug] failed to load. " << strArg3;
}
}
@ -76,4 +68,3 @@ int test( QVector<QVariant> params )
return 0;
}

View File

@ -15,11 +15,7 @@ class QXLSX_EXPORT AbstractOOXmlFile
Q_DECLARE_PRIVATE(AbstractOOXmlFile)
public:
enum CreateFlag
{
F_NewFromScratch,
F_LoadFromExists
};
enum CreateFlag { F_NewFromScratch, F_LoadFromExists };
public:
virtual ~AbstractOOXmlFile();

View File

@ -3,9 +3,8 @@
#ifndef XLSXOOXMLFILE_P_H
#define XLSXOOXMLFILE_P_H
#include "xlsxglobal.h"
#include "xlsxabstractooxmlfile.h"
#include "xlsxglobal.h"
#include "xlsxrelationships_p.h"
QT_BEGIN_NAMESPACE_XLSX

View File

@ -3,8 +3,8 @@
#ifndef XLSXABSTRACTSHEET_H
#define XLSXABSTRACTSHEET_H
#include "xlsxglobal.h"
#include "xlsxabstractooxmlfile.h"
#include "xlsxglobal.h"
QT_BEGIN_NAMESPACE_XLSX

View File

@ -3,15 +3,14 @@
#ifndef XLSXABSTRACTSHEET_P_H
#define XLSXABSTRACTSHEET_P_H
#include <QString>
#include "xlsxabstractooxmlfile_p.h"
#include "xlsxabstractsheet.h"
#include "xlsxdrawing_p.h"
#include "xlsxglobal.h"
#include <memory>
#include "xlsxglobal.h"
#include "xlsxabstractsheet.h"
#include "xlsxabstractooxmlfile_p.h"
#include "xlsxdrawing_p.h"
#include <QString>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -3,18 +3,18 @@
#ifndef QXLSX_XLSXCELL_H
#define QXLSX_XLSXCELL_H
#include "xlsxformat.h"
#include "xlsxglobal.h"
#include <cstdio>
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QVariant>
#include <QDate>
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QTime>
#include "xlsxglobal.h"
#include "xlsxformat.h"
#include <QVariant>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -74,7 +74,6 @@ public:
qint32 styleNumber() const;
static bool isDateType(CellType cellType, const Format &format);
};
QT_END_NAMESPACE_XLSX

View File

@ -3,15 +3,15 @@
#ifndef XLSXCELL_P_H
#define XLSXCELL_P_H
#include <QtGlobal>
#include <QObject>
#include <QList>
#include "xlsxglobal.h"
#include "xlsxcell.h"
#include "xlsxcellrange.h"
#include "xlsxrichstring.h"
#include "xlsxcellformula.h"
#include "xlsxcellrange.h"
#include "xlsxglobal.h"
#include "xlsxrichstring.h"
#include <QList>
#include <QObject>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -21,9 +21,11 @@ class CellPrivate
public:
CellPrivate(Cell *p);
CellPrivate(const CellPrivate *const cp);
public:
Worksheet *parent;
Cell *q_ptr;
public:
Cell::CellType cellType;
QVariant value;

View File

@ -44,6 +44,7 @@ public:
bool saveToXml(QXmlStreamWriter &writer) const;
bool loadFromXml(QXmlStreamReader &reader);
private:
friend class Worksheet;
friend class WorksheetPrivate;

View File

@ -3,9 +3,9 @@
#ifndef XLSXCELLFORMULA_P_H
#define XLSXCELLFORMULA_P_H
#include "xlsxglobal.h"
#include "xlsxcellformula.h"
#include "xlsxcellrange.h"
#include "xlsxglobal.h"
#include <QSharedData>
#include <QString>
@ -15,7 +15,9 @@ QT_BEGIN_NAMESPACE_XLSX
class CellFormulaPrivate : public QSharedData
{
public:
CellFormulaPrivate(const QString &formula, const CellRange &reference, CellFormula::FormulaType type);
CellFormulaPrivate(const QString &formula,
const CellRange &reference,
CellFormula::FormulaType type);
CellFormulaPrivate(const CellFormulaPrivate &other);
~CellFormulaPrivate();

View File

@ -3,16 +3,16 @@
#ifndef CELL_LOCATION_H
#define CELL_LOCATION_H
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QVector>
#include <QList>
#include <QMetaType>
#include "xlsxglobal.h"
#include <memory>
#include "xlsxglobal.h"
#include <QList>
#include <QMetaType>
#include <QObject>
#include <QString>
#include <QVector>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -3,11 +3,11 @@
#ifndef QXLSX_XLSXCELLRANGE_H
#define QXLSX_XLSXCELLRANGE_H
#include <QtGlobal>
#include <QObject>
#include "xlsxglobal.h"
#include "xlsxcellreference.h"
#include "xlsxglobal.h"
#include <QObject>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -49,14 +49,15 @@ public:
}
inline bool operator==(const CellRange &other) const
{
return top==other.top && bottom==other.bottom
&& left == other.left && right == other.right;
return top == other.top && bottom == other.bottom && left == other.left &&
right == other.right;
}
inline bool operator!=(const CellRange &other) const
{
return top!=other.top || bottom!=other.bottom
|| left != other.left || right != other.right;
return top != other.top || bottom != other.bottom || left != other.left ||
right != other.right;
}
private:
void init(const QString &range);

View File

@ -3,10 +3,10 @@
#ifndef QXLSX_XLSXCELLREFERENCE_H
#define QXLSX_XLSXCELLREFERENCE_H
#include <QtGlobal>
#include "xlsxglobal.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
class QXLSX_EXPORT CellReference
@ -35,6 +35,7 @@ public:
{
return _row != other._row || _column != other._column;
}
private:
void init(const QString &cell);
int _row, _column;

View File

@ -3,11 +3,11 @@
#ifndef QXLSX_CHART_H
#define QXLSX_CHART_H
#include <QtGlobal>
#include "xlsxabstractooxmlfile.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xlsxabstractooxmlfile.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -23,31 +23,50 @@ class QXLSX_EXPORT Chart : public AbstractOOXmlFile
public:
enum ChartType { // 16 type of chart (ECMA 376)
CT_NoStatementChart = 0, // Zero is internally used for unknown types
CT_AreaChart, CT_Area3DChart, CT_LineChart,
CT_Line3DChart, CT_StockChart, CT_RadarChart,
CT_ScatterChart, CT_PieChart, CT_Pie3DChart,
CT_DoughnutChart, CT_BarChart, CT_Bar3DChart,
CT_OfPieChart, CT_SurfaceChart, CT_Surface3DChart,
CT_AreaChart,
CT_Area3DChart,
CT_LineChart,
CT_Line3DChart,
CT_StockChart,
CT_RadarChart,
CT_ScatterChart,
CT_PieChart,
CT_Pie3DChart,
CT_DoughnutChart,
CT_BarChart,
CT_Bar3DChart,
CT_OfPieChart,
CT_SurfaceChart,
CT_Surface3DChart,
CT_BubbleChart,
};
enum ChartAxisPos { None = (-1), Left = 0, Right, Top, Bottom };
private:
friend class AbstractSheet;
friend class Worksheet;
friend class Chartsheet;
friend class DrawingAnchor;
private:
Chart(AbstractSheet *parent, CreateFlag flag);
public:
~Chart();
public:
void addSeries(const CellRange &range, AbstractSheet *sheet = NULL, bool headerH = false, bool headerV = false, bool swapHeaders = false);
void addSeries(const CellRange &range,
AbstractSheet *sheet = NULL,
bool headerH = false,
bool headerV = false,
bool swapHeaders = false);
void setChartType(ChartType type);
void setChartStyle(int id);
void setAxisTitle(Chart::ChartAxisPos pos, QString axisTitle);
void setChartTitle(QString strchartTitle);
void setChartLegend(Chart::ChartAxisPos legendPos, bool overlap = false);
void setGridlinesEnable(bool majorGridlinesEnable = false, bool minorGridlinesEnable = false);
public:
bool loadFromXmlFile(QIODevice *device) override;
void saveToXmlFile(QIODevice *device) const override;

View File

@ -3,18 +3,18 @@
#ifndef QXLSX_CHART_P_H
#define QXLSX_CHART_P_H
#include <QObject>
#include <QString>
#include <QVector>
#include <QMap>
#include <QList>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xlsxabstractooxmlfile_p.h"
#include "xlsxchart.h"
#include <memory>
#include "xlsxabstractooxmlfile_p.h"
#include "xlsxchart.h"
#include <QList>
#include <QMap>
#include <QObject>
#include <QString>
#include <QVector>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
QT_BEGIN_NAMESPACE_XLSX
@ -34,22 +34,18 @@ class XlsxAxis
public:
enum Type { T_None = (-1), T_Cat, T_Val, T_Date, T_Ser };
enum AxisPos { None = (-1), Left, Right, Top, Bottom };
public:
XlsxAxis() {}
XlsxAxis( Type t,
XlsxAxis::AxisPos p,
int id,
int crossId,
QString axisTitle = QString())
XlsxAxis(Type t, XlsxAxis::AxisPos p, int id, int crossId, QString axisTitle = QString())
{
type = t;
axisPos = p;
axisId = id;
crossAx = crossId;
if ( !axisTitle.isEmpty() )
{
if (!axisTitle.isEmpty()) {
axisNames[p] = axisTitle;
}
}
@ -73,8 +69,10 @@ public:
public:
bool loadXmlChart(QXmlStreamReader &reader);
bool loadXmlPlotArea(QXmlStreamReader &reader);
protected:
bool loadXmlPlotAreaElement(QXmlStreamReader &reader);
public:
bool loadXmlXxxChart(QXmlStreamReader &reader);
bool loadXmlSer(QXmlStreamReader &reader);
@ -82,11 +80,13 @@ public:
QString loadXmlStrRef(QXmlStreamReader &reader);
bool loadXmlChartTitle(QXmlStreamReader &reader);
bool loadXmlChartLegend(QXmlStreamReader &reader);
protected:
bool loadXmlChartTitleTx(QXmlStreamReader &reader);
bool loadXmlChartTitleTxRich(QXmlStreamReader &reader);
bool loadXmlChartTitleTxRichP(QXmlStreamReader &reader);
bool loadXmlChartTitleTxRichP_R(QXmlStreamReader &reader);
protected:
bool loadXmlAxisCatAx(QXmlStreamReader &reader);
bool loadXmlAxisDateAx(QXmlStreamReader &reader);

View File

@ -3,11 +3,11 @@
#ifndef XLSXCHARTSHEET_H
#define XLSXCHARTSHEET_H
#include <QtGlobal>
#include <QStringList>
#include "xlsxabstractsheet.h"
#include <QStringList>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
class Workbook;

View File

@ -3,11 +3,11 @@
#ifndef XLSXCHARTSHEET_P_H
#define XLSXCHARTSHEET_P_H
#include <QtGlobal>
#include "xlsxglobal.h"
#include "xlsxchartsheet.h"
#include "xlsxabstractsheet_p.h"
#include "xlsxchartsheet.h"
#include "xlsxglobal.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -3,14 +3,14 @@
#ifndef QXLSX_XLSXCOLOR_P_H
#define QXLSX_XLSXCOLOR_P_H
#include <QtGlobal>
#include <QVariant>
#include <QColor>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include "xlsxglobal.h"
#include <QColor>
#include <QVariant>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
class Styles;

View File

@ -3,17 +3,17 @@
#ifndef QXLSX_XLSXCONDITIONALFORMATTING_H
#define QXLSX_XLSXCONDITIONALFORMATTING_H
#include <QtGlobal>
#include <QString>
#include <QList>
#include <QColor>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QSharedDataPointer>
#include "xlsxglobal.h"
#include "xlsxcellrange.h"
#include "xlsxcellreference.h"
#include "xlsxglobal.h"
#include <QColor>
#include <QList>
#include <QSharedDataPointer>
#include <QString>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
class ConditionalFormattingTest;
@ -70,15 +70,7 @@ public:
Highlight_Expression
};
enum ValueObjectType
{
VOT_Formula,
VOT_Max,
VOT_Min,
VOT_Num,
VOT_Percent,
VOT_Percentile
};
enum ValueObjectType { VOT_Formula, VOT_Max, VOT_Min, VOT_Num, VOT_Percent, VOT_Percentile };
public:
ConditionalFormatting();
@ -86,13 +78,32 @@ public:
~ConditionalFormatting();
public:
bool addHighlightCellsRule(HighlightRuleType type, const Format &format, bool stopIfTrue=false);
bool addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const Format &format, bool stopIfTrue=false);
bool addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const QString &formula2, const Format &format, bool stopIfTrue=false);
bool addHighlightCellsRule(HighlightRuleType type,
const Format &format,
bool stopIfTrue = false);
bool addHighlightCellsRule(HighlightRuleType type,
const QString &formula1,
const Format &format,
bool stopIfTrue = false);
bool addHighlightCellsRule(HighlightRuleType type,
const QString &formula1,
const QString &formula2,
const Format &format,
bool stopIfTrue = false);
bool addDataBarRule(const QColor &color, bool showData = true, bool stopIfTrue = false);
bool addDataBarRule(const QColor &color, ValueObjectType type1, const QString &val1, ValueObjectType type2, const QString &val2, bool showData=true, bool stopIfTrue=false);
bool add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue=false);
bool add3ColorScaleRule(const QColor &minColor, const QColor &midColor, const QColor &maxColor, bool stopIfTrue=false);
bool addDataBarRule(const QColor &color,
ValueObjectType type1,
const QString &val1,
ValueObjectType type2,
const QString &val2,
bool showData = true,
bool stopIfTrue = false);
bool
add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue = false);
bool add3ColorScaleRule(const QColor &minColor,
const QColor &midColor,
const QColor &maxColor,
bool stopIfTrue = false);
QList<CellRange> ranges() const;

View File

@ -3,14 +3,14 @@
#ifndef XLSXCONDITIONALFORMATTING_P_H
#define XLSXCONDITIONALFORMATTING_P_H
#include <QSharedData>
#include <QMap>
#include "xlsxcolor_p.h"
#include "xlsxconditionalformatting.h"
#include "xlsxformat.h"
#include <memory>
#include "xlsxconditionalformatting.h"
#include "xlsxformat.h"
#include "xlsxcolor_p.h"
#include <QMap>
#include <QSharedData>
QT_BEGIN_NAMESPACE_XLSX
@ -23,7 +23,9 @@ public:
}
XlsxCfVoData(ConditionalFormatting::ValueObjectType type, const QString &value, bool gte = true)
:type(type), value(value), gte(gte)
: type(type)
, value(value)
, gte(gte)
{
}
@ -69,7 +71,8 @@ public:
XlsxCfRuleData()
: priority(1)
{}
{
}
int priority;
Format dxfFormat;

View File

@ -3,13 +3,13 @@
#ifndef XLSXCONTENTTYPES_H
#define XLSXCONTENTTYPES_H
#include <QtGlobal>
#include "xlsxabstractooxmlfile.h"
#include <QIODevice>
#include <QMap>
#include <QString>
#include <QStringList>
#include <QMap>
#include <QIODevice>
#include "xlsxabstractooxmlfile.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -43,6 +43,7 @@ public:
void saveToXmlFile(QIODevice *device) const override;
bool loadFromXmlFile(QIODevice *device) override;
private:
QMap<QString, QString> m_defaults;
QMap<QString, QString> m_overrides;

View File

@ -3,14 +3,14 @@
#ifndef QXLSX_XLSXDATAVALIDATION_H
#define QXLSX_XLSXDATAVALIDATION_H
#include <QtGlobal>
#include "xlsxglobal.h"
#include <QList>
#include <QSharedDataPointer>
#include <QString>
#include <QList>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xlsxglobal.h"
#include <QtGlobal>
class QXmlStreamReader;
class QXmlStreamWriter;
@ -25,20 +25,9 @@ class DataValidationPrivate;
class QXLSX_EXPORT DataValidation
{
public:
enum ValidationType
{
None,
Whole,
Decimal,
List,
Date,
Time,
TextLength,
Custom
};
enum ValidationType { None, Whole, Decimal, List, Date, Time, TextLength, Custom };
enum ValidationOperator
{
enum ValidationOperator {
Between,
NotBetween,
Equal,
@ -49,16 +38,14 @@ public:
GreaterThanOrEqual
};
enum ErrorStyle
{
Stop,
Warning,
Information
};
enum ErrorStyle { Stop, Warning, Information };
DataValidation();
DataValidation(ValidationType type, ValidationOperator op=Between, const QString &formula1=QString()
, const QString &formula2=QString(), bool allowBlank=false);
DataValidation(ValidationType type,
ValidationOperator op = Between,
const QString &formula1 = QString(),
const QString &formula2 = QString(),
bool allowBlank = false);
DataValidation(const DataValidation &other);
~DataValidation();
@ -96,6 +83,7 @@ public:
bool saveToXml(QXmlStreamWriter &writer) const;
static DataValidation loadFromXml(QXmlStreamReader &reader);
private:
QSharedDataPointer<DataValidationPrivate> d;
};

View File

@ -3,18 +3,22 @@
#ifndef XLSXDATAVALIDATION_P_H
#define XLSXDATAVALIDATION_P_H
#include <QtGlobal>
#include <QSharedData>
#include "xlsxdatavalidation.h"
#include <QSharedData>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
class DataValidationPrivate : public QSharedData
{
public:
DataValidationPrivate();
DataValidationPrivate(DataValidation::ValidationType type, DataValidation::ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank);
DataValidationPrivate(DataValidation::ValidationType type,
DataValidation::ValidationOperator op,
const QString &formula1,
const QString &formula2,
bool allowBlank);
DataValidationPrivate(const DataValidationPrivate &other);
~DataValidationPrivate();

View File

@ -3,15 +3,15 @@
#ifndef QXLSX_XLSXDATETYPE_H
#define QXLSX_XLSXDATETYPE_H
#include <QtGlobal>
#include "xlsxglobal.h"
#include <QDate>
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include "xlsxglobal.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -3,12 +3,12 @@
#ifndef XLSXDOCPROPSAPP_H
#define XLSXDOCPROPSAPP_H
#include <QList>
#include <QStringList>
#include <QMap>
#include "xlsxglobal.h"
#include "xlsxabstractooxmlfile.h"
#include "xlsxglobal.h"
#include <QList>
#include <QMap>
#include <QStringList>
class QIODevice;

View File

@ -3,8 +3,8 @@
#ifndef XLSXDOCPROPSCORE_H
#define XLSXDOCPROPSCORE_H
#include "xlsxglobal.h"
#include "xlsxabstractooxmlfile.h"
#include "xlsxglobal.h"
#include <QMap>
#include <QStringList>

View File

@ -3,15 +3,15 @@
#ifndef QXLSX_XLSXDOCUMENT_H
#define QXLSX_XLSXDOCUMENT_H
#include <QtGlobal>
#include <QObject>
#include <QVariant>
#include "xlsxformat.h"
#include "xlsxglobal.h"
#include "xlsxworksheet.h"
#include <QIODevice>
#include <QImage>
#include "xlsxglobal.h"
#include "xlsxformat.h"
#include "xlsxworksheet.h"
#include <QObject>
#include <QVariant>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -85,8 +85,10 @@ public:
Cell *cellAt(const CellReference &cell) const;
Cell *cellAt(int row, int col) const;
bool defineName(const QString &name, const QString &formula,
const QString &comment=QString(), const QString &scope=QString());
bool defineName(const QString &name,
const QString &formula,
const QString &comment = QString(),
const QString &scope = QString());
CellRange dimension() const;
@ -97,7 +99,8 @@ public:
QStringList sheetNames() const;
bool addSheet(const QString &name = QString(),
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
bool insertSheet(int index, const QString &name = QString(),
bool insertSheet(int index,
const QString &name = QString(),
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
bool selectSheet(const QString &name);
bool selectSheet(int index);
@ -131,7 +134,6 @@ public:
private:
QMap<int, int> getMaximalColumnWidth(int firstRow = 1, int lastRow = INT_MAX);
private:
Q_DISABLE_COPY(Document) // Disables the use of copy constructors and
// assignment operators for the given Class.

View File

@ -3,13 +3,13 @@
#ifndef XLSXDOCUMENT_P_H
#define XLSXDOCUMENT_P_H
#include <QtGlobal>
#include <QMap>
#include "xlsxglobal.h"
#include "xlsxdocument.h"
#include "xlsxworkbook.h"
#include "xlsxcontenttypes_p.h"
#include "xlsxdocument.h"
#include "xlsxglobal.h"
#include "xlsxworkbook.h"
#include <QMap>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -3,12 +3,12 @@
#ifndef QXLSX_DRAWING_H
#define QXLSX_DRAWING_H
#include <QtGlobal>
#include "xlsxabstractooxmlfile.h"
#include "xlsxrelationships_p.h"
#include <QList>
#include <QString>
#include "xlsxrelationships_p.h"
#include "xlsxabstractooxmlfile.h"
#include <QtGlobal>
class QIODevice;
class QXmlStreamWriter;

View File

@ -3,16 +3,16 @@
#ifndef QXLSX_XLSXDRAWINGANCHOR_P_H
#define QXLSX_XLSXDRAWINGANCHOR_P_H
#include <QPoint>
#include <QSize>
#include <QString>
#include <QSharedPointer>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xlsxglobal.h"
#include <memory>
#include "xlsxglobal.h"
#include <QPoint>
#include <QSharedPointer>
#include <QSize>
#include <QString>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
QT_BEGIN_NAMESPACE_XLSX
@ -21,13 +21,12 @@ class MediaFile;
class Chart;
// Helper class
struct XlsxMarker
{
struct XlsxMarker {
XlsxMarker() {}
XlsxMarker(int row, int column, int rowOffset, int colOffset)
:cell(QPoint(row, column)), offset(rowOffset, colOffset)
: cell(QPoint(row, column))
, offset(rowOffset, colOffset)
{
}
int row() const { return cell.x(); }
@ -42,14 +41,7 @@ struct XlsxMarker
class DrawingAnchor
{
public:
enum ObjectType {
GraphicFrame,
Shape,
GroupShape,
ConnectionShape,
Picture,
Unknown
};
enum ObjectType { GraphicFrame, Shape, GroupShape, ConnectionShape, Picture, Unknown };
DrawingAnchor(Drawing *drawing, ObjectType objectType);
virtual ~DrawingAnchor();
@ -78,7 +70,9 @@ protected:
void saveXmlPos(QXmlStreamWriter &writer, const QPoint &pos) const;
void saveXmlExt(QXmlStreamWriter &writer, const QSize &ext) const;
void saveXmlMarker(QXmlStreamWriter &writer, const XlsxMarker &marker, const QString &node) const;
void saveXmlMarker(QXmlStreamWriter &writer,
const XlsxMarker &marker,
const QString &node) const;
void saveXmlObject(QXmlStreamWriter &writer) const;
void saveXmlObjectShape(QXmlStreamWriter &writer) const;
void saveXmlObjectGroupShape(QXmlStreamWriter &writer) const;
@ -92,11 +86,11 @@ protected:
QSharedPointer<Chart> m_chartFile;
int m_id;
public:
int getm_id();
protected:
// liufeij {{
void setObjectShape(const QImage &img); // liufeij

View File

@ -3,15 +3,15 @@
#ifndef QXLSX_FORMAT_H
#define QXLSX_FORMAT_H
#include <QFont>
#include <QColor>
#include <QByteArray>
#include <QList>
#include <QExplicitlySharedDataPointer>
#include <QVariant>
#include "xlsxglobal.h"
#include <QByteArray>
#include <QColor>
#include <QExplicitlySharedDataPointer>
#include <QFont>
#include <QList>
#include <QVariant>
class FormatTest;
QT_BEGIN_NAMESPACE_XLSX
@ -27,15 +27,9 @@ class FormatPrivate;
class QXLSX_EXPORT Format
{
public:
enum FontScript
{
FontScriptNormal,
FontScriptSuper,
FontScriptSub
};
enum FontScript { FontScriptNormal, FontScriptSuper, FontScriptSub };
enum FontUnderline
{
enum FontUnderline {
FontUnderlineNone,
FontUnderlineSingle,
FontUnderlineDouble,
@ -43,8 +37,7 @@ public:
FontUnderlineDoubleAccounting
};
enum HorizontalAlignment
{
enum HorizontalAlignment {
AlignHGeneral,
AlignLeft,
AlignHCenter,
@ -55,8 +48,7 @@ public:
AlignHDistributed
};
enum VerticalAlignment
{
enum VerticalAlignment {
AlignTop,
AlignVCenter,
AlignBottom,
@ -64,8 +56,7 @@ public:
AlignVDistributed
};
enum BorderStyle
{
enum BorderStyle {
BorderNone,
BorderThin,
BorderMedium,
@ -82,16 +73,14 @@ public:
BorderSlantDashDot
};
enum DiagonalBorderType
{
enum DiagonalBorderType {
DiagonalBorderNone,
DiagonalBorderDown,
DiagonalBorderUp,
DiagnoalBorderBoth
};
enum FillPattern
{
enum FillPattern {
PatternNone,
PatternSolid,
PatternMediumGray,
@ -204,7 +193,10 @@ public:
bool operator!=(const Format &format) const;
QVariant property(int propertyId, const QVariant &defaultValue = QVariant()) const;
void setProperty(int propertyId, const QVariant &value, const QVariant &clearValue=QVariant(), bool detach=true);
void setProperty(int propertyId,
const QVariant &value,
const QVariant &clearValue = QVariant(),
bool detach = true);
void clearProperty(int propertyId);
bool hasProperty(int propertyId) const;
@ -243,6 +235,7 @@ public:
void setFillIndex(int index);
void setXfIndex(int index);
void setDxfIndex(int index);
private:
friend class Styles;
friend class ::FormatTest;

View File

@ -2,20 +2,19 @@
#ifndef XLSXFORMAT_P_H
#define XLSXFORMAT_P_H
#include <QtGlobal>
#include <QSharedData>
#include "xlsxformat.h"
#include <QMap>
#include <QSet>
#include "xlsxformat.h"
#include <QSharedData>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
class FormatPrivate : public QSharedData
{
public:
enum FormatType
{
enum FormatType {
FT_Invalid = 0,
FT_NumFmt = 0x01,
FT_Font = 0x02,
@ -124,7 +123,6 @@ public:
QMap<int, QVariant> properties;
};
QT_END_NAMESPACE_XLSX
#endif

View File

@ -4,16 +4,16 @@
#define XLSXGLOBAL_H
#include <cstdio>
#include <string>
#include <iostream>
#include <string>
#include <QtGlobal>
#include <QByteArray>
#include <QIODevice>
#include <QObject>
#include <QString>
#include <QVariant>
#include <QIODevice>
#include <QByteArray>
#include <QStringList>
#include <QVariant>
#include <QtGlobal>
#if defined(QXlsx_SHAREDLIB)
# if defined(QXlsx_EXPORTS)

View File

@ -5,8 +5,8 @@
#include "xlsxglobal.h"
#include <QString>
#include <QByteArray>
#include <QString>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -38,14 +38,13 @@
#include "xlsxglobal.h"
#include <QIODevice>
#include <QList>
#include <QString>
#include <QIODevice>
QT_BEGIN_NAMESPACE_XLSX
struct XlsxRelationship
{
struct XlsxRelationship {
QString id;
QString type;
QString target;
@ -65,7 +64,9 @@ public:
void addDocumentRelationship(const QString &relativeType, const QString &target);
void addPackageRelationship(const QString &relativeType, const QString &target);
void addMsPackageRelationship(const QString &relativeType, const QString &target);
void addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode=QString());
void addWorksheetRelationship(const QString &relativeType,
const QString &target,
const QString &targetMode = QString());
void saveToXmlFile(QIODevice *device) const;
QByteArray saveToXmlData() const;
@ -79,7 +80,9 @@ public:
private:
QList<XlsxRelationship> relationships(const QString &type) const;
void addRelationship(const QString &type, const QString &target, const QString &targetMode=QString());
void addRelationship(const QString &type,
const QString &target,
const QString &targetMode = QString());
QList<XlsxRelationship> m_relationships;
};

View File

@ -25,11 +25,12 @@
#ifndef XLSXRICHSTRING_H
#define XLSXRICHSTRING_H
#include "xlsxglobal.h"
#include "xlsxformat.h"
#include <QVariant>
#include <QStringList>
#include "xlsxglobal.h"
#include <QSharedDataPointer>
#include <QStringList>
#include <QVariant>
QT_BEGIN_NAMESPACE_XLSX
class RichStringPrivate;
@ -60,6 +61,7 @@ public:
operator QVariant() const;
RichString &operator=(const RichString &other);
private:
friend uint qHash(const RichString &rs, uint seed) Q_DECL_NOTHROW;
friend bool operator==(const RichString &rs1, const RichString &rs2);

View File

@ -36,23 +36,24 @@
// We mean it.
//
#include <QHash>
#include <QStringList>
#include <QIODevice>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xlsxabstractooxmlfile.h"
#include "xlsxglobal.h"
#include "xlsxrichstring.h"
#include "xlsxabstractooxmlfile.h"
#include <QHash>
#include <QIODevice>
#include <QStringList>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
QT_BEGIN_NAMESPACE_XLSX
class XlsxSharedStringInfo
{
public:
XlsxSharedStringInfo(int index=0, int count = 1) :
index(index), count(count)
XlsxSharedStringInfo(int index = 0, int count = 1)
: index(index)
, count(count)
{
}

View File

@ -37,8 +37,8 @@
//
#include "xlsxabstractooxmlfile.h"
#include <QString>
#include <QIODevice>
#include <QString>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -36,30 +36,32 @@
// We mean it.
//
#include <QSharedPointer>
#include <QHash>
#include <QIODevice>
#include <QList>
#include <QMap>
#include <QSharedPointer>
#include <QStringList>
#include <QVector>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QIODevice>
#include <QXmlStreamWriter>
// class StylesTest;
#include "xlsxglobal.h"
#include "xlsxformat.h"
#include "xlsxabstractooxmlfile.h"
#include "xlsxformat.h"
#include "xlsxglobal.h"
QT_BEGIN_NAMESPACE_XLSX
class Format;
class XlsxColor;
struct XlsxFormatNumberData
struct XlsxFormatNumberData {
XlsxFormatNumberData()
: formatIndex(0)
{
XlsxFormatNumberData() : formatIndex(0) {}
}
int formatIndex;
QString formatString;
@ -93,7 +95,10 @@ private:
void writeFill(QXmlStreamWriter &writer, const Format &fill, bool isDxf = false) const;
void writeBorders(QXmlStreamWriter &writer) const;
void writeBorder(QXmlStreamWriter &writer, const Format &border, bool isDxf = false) const;
void writeSubBorder(QXmlStreamWriter &writer, const QString &type, int style, const XlsxColor &color) const;
void writeSubBorder(QXmlStreamWriter &writer,
const QString &type,
int style,
const XlsxColor &color) const;
void writeCellXfs(QXmlStreamWriter &writer) const;
void writeDxfs(QXmlStreamWriter &writer) const;
void writeDxf(QXmlStreamWriter &writer, const Format &format) const;
@ -106,7 +111,10 @@ private:
bool readFill(QXmlStreamReader &reader, Format &format);
bool readBorders(QXmlStreamReader &reader);
bool readBorder(QXmlStreamReader &reader, Format &format);
bool readSubBorder(QXmlStreamReader &reader, const QString &name, Format::BorderStyle &style, XlsxColor &color);
bool readSubBorder(QXmlStreamReader &reader,
const QString &name,
Format::BorderStyle &style,
XlsxColor &color);
bool readCellXfs(QXmlStreamReader &reader);
bool readDxfs(QXmlStreamReader &reader);
bool readDxf(QXmlStreamReader &reader);

View File

@ -3,12 +3,12 @@
#ifndef XLSXTHEME_H
#define XLSXTHEME_H
#include <QtGlobal>
#include <QString>
#include <QIODevice>
#include "xlsxabstractooxmlfile.h"
#include <QIODevice>
#include <QString>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
class Theme : public AbstractOOXmlFile

View File

@ -3,19 +3,18 @@
#ifndef XLSXUTILITY_H
#define XLSXUTILITY_H
#include <QtGlobal>
#include "xlsxglobal.h"
#include <QColor>
#include <QDate>
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QPoint>
#include <QString>
#include <QStringList>
#include <QColor>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include <QVariant>
#include "xlsxglobal.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -36,7 +35,9 @@ QString unescapeSheetName(const QString &sheetName);
bool isSpaceReserveNeeded(const QString &string);
QString convertSharedFormula(const QString &rootFormula, const CellReference &rootCell, const CellReference &cell);
QString convertSharedFormula(const QString &rootFormula,
const CellReference &rootCell,
const CellReference &cell);
QT_END_NAMESPACE_XLSX
#endif // XLSXUTILITY_H

View File

@ -3,17 +3,17 @@
#ifndef XLSXWORKBOOK_H
#define XLSXWORKBOOK_H
#include <QtGlobal>
#include <QList>
#include <QImage>
#include <QSharedPointer>
#include <QIODevice>
#include "xlsxabstractooxmlfile.h"
#include "xlsxabstractsheet.h"
#include "xlsxglobal.h"
#include <memory>
#include "xlsxglobal.h"
#include "xlsxabstractooxmlfile.h"
#include "xlsxabstractsheet.h"
#include <QIODevice>
#include <QImage>
#include <QList>
#include <QSharedPointer>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -39,8 +39,11 @@ public:
int sheetCount() const;
AbstractSheet *sheet(int index) const;
AbstractSheet *addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
AbstractSheet *insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
AbstractSheet *addSheet(const QString &name = QString(),
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
AbstractSheet *insertSheet(int index,
const QString &name = QString(),
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
bool renameSheet(int index, const QString &name);
bool deleteSheet(int index);
bool copySheet(int index, const QString &newName = QString());
@ -50,7 +53,10 @@ public:
bool setActiveSheet(int index);
// void addChart();
bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString());
bool defineName(const QString &name,
const QString &formula,
const QString &comment = QString(),
const QString &scope = QString());
bool isDate1904() const;
void setDate1904(bool date1904);
bool isStringsToNumbersEnabled() const;
@ -87,7 +93,9 @@ private:
QList<Drawing *> drawings();
QList<QSharedPointer<AbstractSheet>> getSheetsByTypes(AbstractSheet::SheetType type) const;
QStringList worksheetNames() const;
AbstractSheet *addSheet(const QString &name, int sheetId, AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
AbstractSheet *addSheet(const QString &name,
int sheetId,
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
};
QT_END_NAMESPACE_XLSX

View File

@ -3,27 +3,32 @@
#ifndef XLSXWORKBOOK_P_H
#define XLSXWORKBOOK_P_H
#include <QtGlobal>
#include "xlsxabstractooxmlfile_p.h"
#include "xlsxrelationships_p.h"
#include "xlsxsimpleooxmlfile_p.h"
#include "xlsxtheme_p.h"
#include "xlsxworkbook.h"
#include <QSharedPointer>
#include <QStringList>
#include "xlsxworkbook.h"
#include "xlsxabstractooxmlfile_p.h"
#include "xlsxtheme_p.h"
#include "xlsxsimpleooxmlfile_p.h"
#include "xlsxrelationships_p.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
struct XlsxDefineNameData
{
struct XlsxDefineNameData {
XlsxDefineNameData()
: sheetId(-1)
{}
XlsxDefineNameData(const QString &name, const QString &formula, const QString &comment, int sheetId=-1)
:name(name), formula(formula), comment(comment), sheetId(sheetId)
{
}
XlsxDefineNameData(const QString &name,
const QString &formula,
const QString &comment,
int sheetId = -1)
: name(name)
, formula(formula)
, comment(comment)
, sheetId(sheetId)
{
}
QString name;
QString formula;

View File

@ -3,22 +3,22 @@
#ifndef XLSXWORKSHEET_H
#define XLSXWORKSHEET_H
#include <QtGlobal>
#include <QObject>
#include <QStringList>
#include <QMap>
#include <QVariant>
#include <QPointF>
#include <QIODevice>
#include <QDateTime>
#include <QUrl>
#include <QImage>
#include "xlsxabstractsheet.h"
#include "xlsxcell.h"
#include "xlsxcelllocation.h"
#include "xlsxcellrange.h"
#include "xlsxcellreference.h"
#include "xlsxcelllocation.h"
#include <QDateTime>
#include <QIODevice>
#include <QImage>
#include <QMap>
#include <QObject>
#include <QPointF>
#include <QStringList>
#include <QUrl>
#include <QVariant>
#include <QtGlobal>
class WorksheetTest;
@ -51,25 +51,45 @@ public:
~Worksheet();
public:
bool write(const CellReference &row_column, const QVariant &value, const Format &format=Format());
bool write(const CellReference &row_column,
const QVariant &value,
const Format &format = Format());
bool write(int row, int column, const QVariant &value, const Format &format = Format());
QVariant read(const CellReference &row_column) const;
QVariant read(int row, int column) const;
bool writeString(const CellReference &row_column, const QString &value, const Format &format=Format());
bool writeString(const CellReference &row_column,
const QString &value,
const Format &format = Format());
bool writeString(int row, int column, const QString &value, const Format &format = Format());
bool writeString(const CellReference &row_column, const RichString &value, const Format &format=Format());
bool writeString(const CellReference &row_column,
const RichString &value,
const Format &format = Format());
bool writeString(int row, int column, const RichString &value, const Format &format = Format());
bool writeInlineString(const CellReference &row_column, const QString &value, const Format &format=Format());
bool writeInlineString(int row, int column, const QString &value, const Format &format=Format());
bool writeInlineString(const CellReference &row_column,
const QString &value,
const Format &format = Format());
bool writeInlineString(int row,
int column,
const QString &value,
const Format &format = Format());
bool writeNumeric(const CellReference &row_column, double value, const Format &format=Format());
bool writeNumeric(const CellReference &row_column,
double value,
const Format &format = Format());
bool writeNumeric(int row, int column, double value, const Format &format = Format());
bool writeFormula(const CellReference &row_column, const CellFormula &formula, const Format &format=Format(), double result=0);
bool writeFormula(int row, int column, const CellFormula &formula, const Format &format=Format(), double result=0);
bool writeFormula(const CellReference &row_column,
const CellFormula &formula,
const Format &format = Format(),
double result = 0);
bool writeFormula(int row,
int column,
const CellFormula &formula,
const Format &format = Format(),
double result = 0);
bool writeBlank(const CellReference &row_column, const Format &format = Format());
bool writeBlank(int row, int column, const Format &format = Format());
@ -77,18 +97,32 @@ public:
bool writeBool(const CellReference &row_column, bool value, const Format &format = Format());
bool writeBool(int row, int column, bool value, const Format &format = Format());
bool writeDateTime(const CellReference &row_column, const QDateTime& dt, const Format &format=Format());
bool writeDateTime(const CellReference &row_column,
const QDateTime &dt,
const Format &format = Format());
bool writeDateTime(int row, int column, const QDateTime &dt, const Format &format = Format());
// dev67
bool writeDate(const CellReference &row_column, const QDate& dt, const Format &format=Format());
bool writeDate(const CellReference &row_column,
const QDate &dt,
const Format &format = Format());
bool writeDate(int row, int column, const QDate &dt, const Format &format = Format());
bool writeTime(const CellReference &row_column, const QTime& t, const Format &format=Format());
bool
writeTime(const CellReference &row_column, const QTime &t, const Format &format = Format());
bool writeTime(int row, int column, const QTime &t, const Format &format = Format());
bool writeHyperlink(const CellReference &row_column, const QUrl &url, const Format &format=Format(), const QString &display=QString(), const QString &tip=QString());
bool writeHyperlink(int row, int column, const QUrl &url, const Format &format=Format(), const QString &display=QString(), const QString &tip=QString());
bool writeHyperlink(const CellReference &row_column,
const QUrl &url,
const Format &format = Format(),
const QString &display = QString(),
const QString &tip = QString());
bool writeHyperlink(int row,
int column,
const QUrl &url,
const Format &format = Format(),
const QString &display = QString(),
const QString &tip = QString());
bool addDataValidation(const DataValidation &validation);
bool addConditionalFormatting(const ConditionalFormatting &cf);

View File

@ -3,21 +3,20 @@
#ifndef XLSXWORKSHEET_P_H
#define XLSXWORKSHEET_P_H
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QVector>
#include <QImage>
#include <QSharedPointer>
#include <QRegularExpression>
#include "xlsxworksheet.h"
#include "xlsxabstractsheet_p.h"
#include "xlsxcell.h"
#include "xlsxdatavalidation.h"
#include "xlsxconditionalformatting.h"
#include "xlsxcellformula.h"
#include "xlsxconditionalformatting.h"
#include "xlsxdatavalidation.h"
#include "xlsxworksheet.h"
#include <QImage>
#include <QObject>
#include <QRegularExpression>
#include <QSharedPointer>
#include <QString>
#include <QVector>
#include <QtGlobal>
class QXmlStreamWriter;
class QXmlStreamReader;
@ -30,19 +29,20 @@ const int XLSX_STRING_MAX = 32767;
class SharedStrings;
struct XlsxHyperlinkData
{
enum LinkType
{
External,
Internal
};
struct XlsxHyperlinkData {
enum LinkType { External, Internal };
XlsxHyperlinkData(LinkType linkType=External, const QString &target=QString(), const QString &location=QString()
, const QString &display=QString(), const QString &tip=QString())
:linkType(linkType), target(target), location(location), display(display), tooltip(tip)
XlsxHyperlinkData(LinkType linkType = External,
const QString &target = QString(),
const QString &location = QString(),
const QString &display = QString(),
const QString &tip = QString())
: linkType(linkType)
, target(target)
, location(location)
, display(display)
, tooltip(tip)
{
}
LinkType linkType;
@ -53,26 +53,28 @@ struct XlsxHyperlinkData
};
// ECMA-376 Part1 18.3.1.81
struct XlsxSheetFormatProps
{
XlsxSheetFormatProps(int baseColWidth = 8,
struct XlsxSheetFormatProps {
XlsxSheetFormatProps(
int baseColWidth = 8,
bool customHeight = false,
double defaultColWidth = 8.430f, // https://learn.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths
double defaultColWidth =
8.430f, // https://learn.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths
double defaultRowHeight = 15,
quint8 outlineLevelCol = 0,
quint8 outlineLevelRow = 0,
bool thickBottom = false,
bool thickTop = false,
bool zeroHeight = false) :
baseColWidth(baseColWidth),
customHeight(customHeight),
defaultColWidth(defaultColWidth),
defaultRowHeight(defaultRowHeight),
outlineLevelCol(outlineLevelCol),
outlineLevelRow(outlineLevelRow),
thickBottom(thickBottom),
thickTop(thickTop),
zeroHeight(zeroHeight) {
bool zeroHeight = false)
: baseColWidth(baseColWidth)
, customHeight(customHeight)
, defaultColWidth(defaultColWidth)
, defaultRowHeight(defaultRowHeight)
, outlineLevelCol(outlineLevelCol)
, outlineLevelRow(outlineLevelRow)
, thickBottom(thickBottom)
, thickTop(thickTop)
, zeroHeight(zeroHeight)
{
}
int baseColWidth;
@ -86,13 +88,15 @@ struct XlsxSheetFormatProps
bool zeroHeight;
};
struct XlsxRowInfo
{
XlsxRowInfo(double height=0, const Format &format=Format(), bool hidden=false) :
customHeight(false), height(height), format(format), hidden(hidden), outlineLevel(0)
struct XlsxRowInfo {
XlsxRowInfo(double height = 0, const Format &format = Format(), bool hidden = false)
: customHeight(false)
, height(height)
, format(format)
, hidden(hidden)
, outlineLevel(0)
, collapsed(false)
{
}
bool customHeight;
@ -103,25 +107,23 @@ struct XlsxRowInfo
bool collapsed;
};
struct XlsxColumnInfo
{
struct XlsxColumnInfo {
XlsxColumnInfo(int firstColumn, // = 0,
int lastColumn, // = 1,
bool isSetWidth,
double width = 0,
const Format &format = Format(),
bool hidden = false)
: width(width),
format(format),
firstColumn(firstColumn),
lastColumn(lastColumn),
outlineLevel(0),
isSetWidth(isSetWidth),
customWidth(false),
hidden(hidden),
collapsed(false)
: width(width)
, format(format)
, firstColumn(firstColumn)
, lastColumn(lastColumn)
, outlineLevel(0)
, isSetWidth(isSetWidth)
, customWidth(false)
, hidden(hidden)
, collapsed(false)
{
}
double width;
@ -152,7 +154,10 @@ public:
void validateDimension();
void saveXmlSheetData(QXmlStreamWriter &writer) const;
void saveXmlCellData(QXmlStreamWriter &writer, int row, int col, std::shared_ptr<Cell> cell) const;
void saveXmlCellData(QXmlStreamWriter &writer,
int row,
int col,
std::shared_ptr<Cell> cell) const;
void saveXmlMergeCells(QXmlStreamWriter &writer) const;
void saveXmlHyperlinks(QXmlStreamWriter &writer) const;
void saveXmlDrawings(QXmlStreamWriter &writer) const;
@ -244,7 +249,6 @@ public:
QRegularExpression urlPattern;
private:
static double calculateColWidth(int characters);
};

View File

@ -3,12 +3,11 @@
#ifndef QXLSX_XLSXZIPREADER_P_H
#define QXLSX_XLSXZIPREADER_P_H
#include <QScopedPointer>
#include <QStringList>
#include <QIODevice>
#include "xlsxglobal.h"
#include <QIODevice>
#include <QScopedPointer>
#include <QStringList>
#include <QVector>
class QZipReader;

View File

@ -3,12 +3,12 @@
#ifndef QXLSX_ZIPWRITER_H
#define QXLSX_ZIPWRITER_H
#include <QtGlobal>
#include <QString>
#include <QIODevice>
#include "xlsxglobal.h"
#include <QIODevice>
#include <QString>
#include <QtGlobal>
class QZipWriter;
QT_BEGIN_NAMESPACE_XLSX

View File

@ -1,18 +1,22 @@
// xlsxabstractooxmlfile.cpp
#include <QtGlobal>
#include "xlsxabstractooxmlfile.h"
#include "xlsxabstractooxmlfile_p.h"
#include <QBuffer>
#include <QByteArray>
#include "xlsxabstractooxmlfile.h"
#include "xlsxabstractooxmlfile_p.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
AbstractOOXmlFilePrivate::AbstractOOXmlFilePrivate(AbstractOOXmlFile *q, AbstractOOXmlFile::CreateFlag flag=AbstractOOXmlFile::F_NewFromScratch)
: relationships(new Relationships), flag(flag), q_ptr(q)
AbstractOOXmlFilePrivate::AbstractOOXmlFilePrivate(
AbstractOOXmlFile *q,
AbstractOOXmlFile::CreateFlag flag = AbstractOOXmlFile::F_NewFromScratch)
: relationships(new Relationships)
, flag(flag)
, q_ptr(q)
{
}
AbstractOOXmlFilePrivate::~AbstractOOXmlFilePrivate()
@ -38,7 +42,6 @@ AbstractOOXmlFile::AbstractOOXmlFile(CreateFlag flag)
AbstractOOXmlFile::AbstractOOXmlFile(AbstractOOXmlFilePrivate *d)
: d_ptr(d)
{
}
AbstractOOXmlFile::~AbstractOOXmlFile()
@ -83,7 +86,6 @@ QString AbstractOOXmlFile::filePath() const
return d->filePathInPackage;
}
/*!
* \internal
*/
@ -93,5 +95,4 @@ Relationships *AbstractOOXmlFile::relationships() const
return d->relationships;
}
QT_END_NAMESPACE_XLSX

View File

@ -1,11 +1,12 @@
// xlsxabstractsheet.cpp
#include <QtGlobal>
#include "xlsxabstractsheet.h"
#include "xlsxabstractsheet_p.h"
#include "xlsxworkbook.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
AbstractSheetPrivate::AbstractSheetPrivate(AbstractSheet *p, AbstractSheet::CreateFlag flag)
@ -15,9 +16,7 @@ AbstractSheetPrivate::AbstractSheetPrivate(AbstractSheet *p, AbstractSheet::Crea
sheetState = AbstractSheet::SS_Visible;
}
AbstractSheetPrivate::~AbstractSheetPrivate()
{
}
AbstractSheetPrivate::~AbstractSheetPrivate() {}
/*!
\class AbstractSheet
@ -52,15 +51,17 @@ AbstractSheetPrivate::~AbstractSheetPrivate()
/*!
* \internal
*/
AbstractSheet::AbstractSheet(const QString &name, int id, Workbook *workbook, AbstractSheetPrivate *d) :
AbstractOOXmlFile(d)
AbstractSheet::AbstractSheet(const QString &name,
int id,
Workbook *workbook,
AbstractSheetPrivate *d)
: AbstractOOXmlFile(d)
{
d_func()->name = name;
d_func()->id = id;
d_func()->workbook = workbook;
}
/*!
* Returns the name of the sheet.
*/

View File

@ -1,27 +1,27 @@
// xlsxcell.cpp
#include <cmath>
#include <QtGlobal>
#include <QDebug>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include "xlsxcell.h"
#include "xlsxcell_p.h"
#include "xlsxformat.h"
#include "xlsxformat_p.h"
#include "xlsxutility_p.h"
#include "xlsxworksheet.h"
#include "xlsxworkbook.h"
#include "xlsxworksheet.h"
#include <cmath>
#include <QDate>
#include <QDateTime>
#include <QDebug>
#include <QTime>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
CellPrivate::CellPrivate(Cell *p) :
q_ptr(p)
CellPrivate::CellPrivate(Cell *p)
: q_ptr(p)
{
}
CellPrivate::CellPrivate(const CellPrivate *const cp)
@ -33,7 +33,6 @@ CellPrivate::CellPrivate(const CellPrivate * const cp)
, richString(cp->richString)
, styleNumber(cp->styleNumber)
{
}
/*!
@ -62,8 +61,8 @@ Cell::Cell(const QVariant &data,
CellType type,
const Format &format,
Worksheet *parent,
qint32 styleIndex ) :
d_ptr(new CellPrivate(this))
qint32 styleIndex)
: d_ptr(new CellPrivate(this))
{
d_ptr->value = data;
d_ptr->cellType = type;
@ -75,8 +74,8 @@ Cell::Cell(const QVariant &data,
/*!
* \internal
*/
Cell::Cell(const Cell * const cell):
d_ptr(new CellPrivate(cell->d_ptr))
Cell::Cell(const Cell *const cell)
: d_ptr(new CellPrivate(cell->d_ptr))
{
d_ptr->q_ptr = this;
}
@ -122,48 +121,32 @@ QVariant Cell::readValue() const
Format fmt = this->format();
if (isDateTime())
{
if (isDateTime()) {
QVariant vDT = dateTime();
if ( vDT.isNull() )
{
if (vDT.isNull()) {
return QVariant();
}
// https://github.com/QtExcel/QXlsx/issues/171
// https://www.qt.io/blog/whats-new-in-qmetatype-qvariant
#if QT_VERSION >= 0x060000 // Qt 6.0 or over
if ( vDT.metaType().id() == QMetaType::QDateTime )
{
if (vDT.metaType().id() == QMetaType::QDateTime) {
ret = vDT;
}
else if ( vDT.metaType().id() == QMetaType::QDate )
{
} else if (vDT.metaType().id() == QMetaType::QDate) {
ret = vDT;
}
else if ( vDT.metaType().id() == QMetaType::QTime )
{
} else if (vDT.metaType().id() == QMetaType::QTime) {
ret = vDT;
}
else
{
} else {
return QVariant();
}
#else
if ( vDT.type() == QVariant::DateTime )
{
if (vDT.type() == QVariant::DateTime) {
ret = vDT;
}
else if ( vDT.type() == QVariant::Date )
{
} else if (vDT.type() == QVariant::Date) {
ret = vDT;
}
else if ( vDT.type() == QVariant::Time )
{
} else if (vDT.type() == QVariant::Time) {
ret = vDT;
}
else
{
} else {
return QVariant();
}
#endif
@ -203,13 +186,13 @@ QVariant Cell::readValue() const
// double dHour = deciamlPointValue1 * (double(1.0) / double(24.0));
// int hour = int(dHour);
// double deciamlPointValue2 = deciamlPointValue1 - (double(hour) * (double(1.0) / double(24.0)));
// double dMin = deciamlPointValue2 * (double(1.0) / double(60.0));
// int min = int(dMin);
// double deciamlPointValue2 = deciamlPointValue1 - (double(hour) * (double(1.0) /
// double(24.0))); double dMin = deciamlPointValue2 * (double(1.0) / double(60.0)); int min
// = int(dMin);
// double deciamlPointValue3 = deciamlPointValue2 - (double(min) * (double(1.0) / double(60.0)));
// double dSec = deciamlPointValue3 * (double(1.0) / double(60.0));
// int sec = int(dSec);
// double deciamlPointValue3 = deciamlPointValue2 - (double(min) * (double(1.0) /
// double(60.0))); double dSec = deciamlPointValue3 * (double(1.0) / double(60.0)); int sec
// = int(dSec);
// int totalHour = hour + (day * 24);
@ -224,8 +207,7 @@ QVariant Cell::readValue() const
// */
}
if (hasFormula())
{
if (hasFormula()) {
QString formulaString = this->formula().formulaText();
ret = formulaString;
return ret; // return formula string
@ -278,14 +260,8 @@ bool Cell::isDateTime() const
bool isDateTimeFormat = d->format.isDateTimeFormat(); // datetime format
// dev67
if ( cellType == NumberType ||
cellType == DateType ||
cellType == CustomType )
{
if ( dValue >= 0 &&
isValidFormat &&
isDateTimeFormat )
{
if (cellType == NumberType || cellType == DateType || cellType == CustomType) {
if (dValue >= 0 && isValidFormat && isDateTimeFormat) {
return true;
}
}
@ -311,8 +287,7 @@ QVariant Cell::dateTime() const
{
Q_D(const Cell);
if (!isDateTime())
{
if (!isDateTime()) {
return QVariant();
}
@ -332,10 +307,8 @@ bool Cell::isRichString() const
{
Q_D(const Cell);
if ( d->cellType != SharedStringType &&
d->cellType != InlineStringType &&
d->cellType != StringType )
{
if (d->cellType != SharedStringType && d->cellType != InlineStringType &&
d->cellType != StringType) {
return false;
}
@ -352,10 +325,7 @@ qint32 Cell::styleNumber() const
bool Cell::isDateType(CellType cellType, const Format &format)
{
if ( cellType == NumberType ||
cellType == DateType ||
cellType == CustomType )
{
if (cellType == NumberType || cellType == DateType || cellType == CustomType) {
return format.isValid() && format.isDateTimeFormat();
}
return false;

View File

@ -1,20 +1,27 @@
// xlsxcellformula.cpp
#include <QtGlobal>
#include "xlsxcellformula.h"
#include "xlsxcellformula_p.h"
#include "xlsxutility_p.h"
#include <QDebug>
#include <QObject>
#include <QString>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>
#include "xlsxcellformula.h"
#include "xlsxcellformula_p.h"
#include "xlsxutility_p.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
CellFormulaPrivate::CellFormulaPrivate(const QString &formula_, const CellRange &ref_, CellFormula::FormulaType type_)
:formula(formula_), type(type_), reference(ref_), ca(false), si(0)
CellFormulaPrivate::CellFormulaPrivate(const QString &formula_,
const CellRange &ref_,
CellFormula::FormulaType type_)
: formula(formula_)
, type(type_)
, reference(ref_)
, ca(false)
, si(0)
{
// Remove the formula '=' sign if exists
if (formula.startsWith(QLatin1String("=")))
@ -25,16 +32,15 @@ CellFormulaPrivate::CellFormulaPrivate(const QString &formula_, const CellRange
CellFormulaPrivate::CellFormulaPrivate(const CellFormulaPrivate &other)
: QSharedData(other)
, formula(other.formula), type(other.type), reference(other.reference)
, ca(other.ca), si(other.si)
, formula(other.formula)
, type(other.type)
, reference(other.reference)
, ca(other.ca)
, si(other.si)
{
}
CellFormulaPrivate::~CellFormulaPrivate()
{
}
CellFormulaPrivate::~CellFormulaPrivate() {}
/*!
\class CellFormula
@ -65,7 +71,6 @@ CellFormula::CellFormula()
CellFormula::CellFormula(const char *formula, FormulaType type)
: d(new CellFormulaPrivate(QString::fromLatin1(formula), CellRange(), type))
{
}
/*!
@ -74,7 +79,6 @@ CellFormula::CellFormula(const char *formula, FormulaType type)
CellFormula::CellFormula(const QString &formula, FormulaType type)
: d(new CellFormulaPrivate(formula, CellRange(), type))
{
}
/*!
@ -83,7 +87,6 @@ CellFormula::CellFormula(const QString &formula, FormulaType type)
CellFormula::CellFormula(const QString &formula, const CellRange &ref, FormulaType type)
: d(new CellFormulaPrivate(formula, ref, type))
{
}
/*!
@ -107,10 +110,7 @@ CellFormula &CellFormula::operator =(const CellFormula &other)
/*!
* Destroys this formula.
*/
CellFormula::~CellFormula()
{
}
CellFormula::~CellFormula() {}
/*!
* Returns the type of the formula.
@ -257,8 +257,7 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const
// shared (Shared Formula)
QString t;
switch (d->type)
{
switch (d->type) {
case CellFormula::ArrayType:
t = QStringLiteral("array");
break;
@ -282,8 +281,7 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const
// character node of this element.
writer.writeStartElement(QStringLiteral("f"));
if (!t.isEmpty())
{
if (!t.isEmpty()) {
writer.writeAttribute(QStringLiteral("t"), t); // write type(t)
}
@ -297,12 +295,9 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const
// The possible values for this attribute are defined by the ST_Ref
// simple type (§18.18.62).
if ( d->type == CellFormula::SharedType ||
d->type == CellFormula::ArrayType ||
d->type == CellFormula::DataTableType )
{
if (d->reference.isValid())
{
if (d->type == CellFormula::SharedType || d->type == CellFormula::ArrayType ||
d->type == CellFormula::DataTableType) {
if (d->reference.isValid()) {
writer.writeAttribute(QStringLiteral("ref"), d->reference.toString());
}
}
@ -320,8 +315,7 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const
// An instance of a datatype that is defined as ·boolean· can have the
// following legal literals {true, false, 1, 0}.
if (d->ca)
{
if (d->ca) {
writer.writeAttribute(QStringLiteral("ca"), QStringLiteral("1"));
}
@ -337,14 +331,12 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const
// what the formula expression should be based on the cell's relative
// location to the master formula cell.
if (d->type == CellFormula::SharedType)
{
if (d->type == CellFormula::SharedType) {
int si = d->si;
writer.writeAttribute(QStringLiteral("si"), QString::number(si));
}
if (!d->formula.isEmpty())
{
if (!d->formula.isEmpty()) {
QString strFormula = d->formula;
writer.writeCharacters(strFormula); // write formula
}
@ -371,17 +363,13 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader)
//
if (typeString == QLatin1String("array")) {
d->type = ArrayType;
}
else if (typeString == QLatin1String("shared")) {
} else if (typeString == QLatin1String("shared")) {
d->type = SharedType;
}
else if (typeString == QLatin1String("normal")) {
} else if (typeString == QLatin1String("normal")) {
d->type = NormalType;
}
else if (typeString == QLatin1String("dataTable")) {
} else if (typeString == QLatin1String("dataTable")) {
d->type = DataTableType;
}
else {
} else {
/*
// undefined type
// qDebug() << "Undefined type" << typeString;
@ -399,12 +387,9 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader)
// ref (Range of Cells)
// Range of cells which the formula applies to.
// Only required for shared formula, array formula or data table.
if ( d->type == CellFormula::SharedType ||
d->type == CellFormula::ArrayType ||
d->type == CellFormula::DataTableType )
{
if (attributes.hasAttribute(QLatin1String("ref")))
{
if (d->type == CellFormula::SharedType || d->type == CellFormula::ArrayType ||
d->type == CellFormula::DataTableType) {
if (attributes.hasAttribute(QLatin1String("ref"))) {
QString refString = attributes.value(QLatin1String("ref")).toString();
d->reference = CellRange(refString);
}
@ -416,13 +401,11 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader)
// Optional attribute to optimize load performance by sharing formulas.
// When a formula is a shared formula (t value is shared) then this value
// indicates the group to which this particular cell's formula belongs.
if ( d->type == CellFormula::SharedType )
{
if (d->type == CellFormula::SharedType) {
QString ca = attributes.value(QLatin1String("si")).toString();
d->ca = parseXsdBoolean(ca, false);
if (attributes.hasAttribute(QLatin1String("si")))
{
if (attributes.hasAttribute(QLatin1String("si"))) {
d->si = attributes.value(QLatin1String("si")).toInt();
}
}
@ -437,8 +420,7 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader)
*/
bool CellFormula::operator==(const CellFormula &formula) const
{
return d->formula == formula.d->formula && d->type == formula.d->type
&& d->si ==formula.d->si;
return d->formula == formula.d->formula && d->type == formula.d->type && d->si == formula.d->si;
}
/*!
@ -446,8 +428,7 @@ bool CellFormula::operator ==(const CellFormula &formula) const
*/
bool CellFormula::operator!=(const CellFormula &formula) const
{
return d->formula != formula.d->formula || d->type != formula.d->type
|| d->si !=formula.d->si;
return d->formula != formula.d->formula || d->type != formula.d->type || d->si != formula.d->si;
}
QT_END_NAMESPACE_XLSX

View File

@ -1,14 +1,15 @@
// xlsxcelllocation.cpp
#include <QtGlobal>
#include "xlsxcelllocation.h"
#include "xlsxcell.h"
#include "xlsxglobal.h"
#include <QList>
#include <QObject>
#include <QString>
#include <QVector>
#include <QList>
#include "xlsxglobal.h"
#include "xlsxcell.h"
#include "xlsxcelllocation.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -1,13 +1,14 @@
// xlsxcellrange.cpp
#include <QtGlobal>
#include <QString>
#include <QPoint>
#include <QStringList>
#include "xlsxcellrange.h"
#include "xlsxcellreference.h"
#include <QPoint>
#include <QString>
#include <QStringList>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
/*!
@ -24,7 +25,10 @@ QT_BEGIN_NAMESPACE_XLSX
whose rowCount() and columnCount() are 0.
*/
CellRange::CellRange()
: top(-1), left(-1), bottom(-2), right(-2)
: top(-1)
, left(-1)
, bottom(-2)
, right(-2)
{
}
@ -35,13 +39,18 @@ CellRange::CellRange()
\sa topRow(), leftColumn(), bottomRow(), rightColumn()
*/
CellRange::CellRange(int top, int left, int bottom, int right)
: top(top), left(left), bottom(bottom), right(right)
: top(top)
, left(left)
, bottom(bottom)
, right(right)
{
}
CellRange::CellRange(const CellReference &topLeft, const CellReference &bottomRight)
: top(topLeft.row()), left(topLeft.column())
, bottom(bottomRight.row()), right(bottomRight.column())
: top(topLeft.row())
, left(topLeft.column())
, bottom(bottomRight.row())
, right(bottomRight.column())
{
}
@ -87,16 +96,17 @@ void CellRange::init(const QString &range)
other range.
*/
CellRange::CellRange(const CellRange &other)
: top(other.top), left(other.left), bottom(other.bottom), right(other.right)
: top(other.top)
, left(other.left)
, bottom(other.bottom)
, right(other.right)
{
}
/*!
Destroys the range.
*/
CellRange::~CellRange()
{
}
CellRange::~CellRange() {}
/*!
Convert the range to string notation, such as "A1:B5".

View File

@ -1,10 +1,10 @@
// xlsxcellreference.cpp
#include "xlsxcellreference.h"
#include <QStringList>
#include <QMap>
#include <QMap>
#include <QRegularExpression>
#include <QStringList>
QT_BEGIN_NAMESPACE_XLSX
@ -12,12 +12,16 @@ namespace {
int intPow(int x, int p)
{
if (p == 0) return 1;
if (p == 1) return x;
if (p == 0)
return 1;
if (p == 1)
return x;
int tmp = intPow(x, p / 2);
if (p%2 == 0) return tmp * tmp;
else return x * tmp * tmp;
if (p % 2 == 0)
return tmp * tmp;
else
return x * tmp * tmp;
}
QString col_to_name(int col_num)
@ -66,7 +70,8 @@ int col_from_name(const QString &col_str)
Constructs an invalid Cell Reference
*/
CellReference::CellReference()
: _row(-1), _column(-1)
: _row(-1)
, _column(-1)
{
}
@ -74,7 +79,8 @@ CellReference::CellReference()
Constructs the Reference from the given \a row, and \a column.
*/
CellReference::CellReference(int row, int column)
: _row(row), _column(column)
: _row(row)
, _column(column)
{
}
@ -113,16 +119,15 @@ void CellReference::init(const QString &cell_str)
other Reference.
*/
CellReference::CellReference(const CellReference &other)
: _row(other._row), _column(other._column)
: _row(other._row)
, _column(other._column)
{
}
/*!
Destroys the Reference.
*/
CellReference::~CellReference()
{
}
CellReference::~CellReference() {}
/*!
Convert the Reference to string notation, such as "A1" or "$A$1".

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,29 @@
// xlsxchartsheet.cpp
#include <QtGlobal>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDir>
#include "xlsxchartsheet.h"
#include "xlsxchart.h"
#include "xlsxchartsheet_p.h"
#include "xlsxworkbook.h"
#include "xlsxutility_p.h"
#include "xlsxdrawing_p.h"
#include "xlsxdrawinganchor_p.h"
#include "xlsxchart.h"
#include "xlsxutility_p.h"
#include "xlsxworkbook.h"
#include <QDir>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
ChartsheetPrivate::ChartsheetPrivate(Chartsheet *p, Chartsheet::CreateFlag flag)
: AbstractSheetPrivate(p, flag), chart(0)
{
}
ChartsheetPrivate::~ChartsheetPrivate()
: AbstractSheetPrivate(p, flag)
, chart(0)
{
}
ChartsheetPrivate::~ChartsheetPrivate() {}
/*!
\class Chartsheet
\inmodule QtXlsx
@ -39,11 +38,11 @@ Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFl
{
setSheetType(ST_ChartSheet);
if (flag == Chartsheet::F_NewFromScratch)
{
if (flag == Chartsheet::F_NewFromScratch) {
d_func()->drawing = std::make_shared<Drawing>(this, flag);
DrawingAbsoluteAnchor *anchor = new DrawingAbsoluteAnchor(drawing(), DrawingAnchor::Picture);
DrawingAbsoluteAnchor *anchor =
new DrawingAbsoluteAnchor(drawing(), DrawingAnchor::Picture);
anchor->pos = QPoint(0, 0);
anchor->ext = QSize(9293679, 6068786);
@ -73,9 +72,7 @@ Chartsheet *Chartsheet::copy(const QString &distName, int distId) const
/*!
* Destroys this workssheet.
*/
Chartsheet::~Chartsheet()
{
}
Chartsheet::~Chartsheet() {}
/*!
* Returns the chart object of the sheet.
@ -95,8 +92,11 @@ void Chartsheet::saveToXmlFile(QIODevice *device) const
QXmlStreamWriter writer(device);
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeDefaultNamespace(QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeNamespace(QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), QStringLiteral("r"));
writer.writeDefaultNamespace(
QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeNamespace(
QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
QStringLiteral("r"));
writer.writeStartElement(QStringLiteral("chartsheet"));
writer.writeStartElement(QStringLiteral("sheetViews"));
@ -106,10 +106,12 @@ void Chartsheet::saveToXmlFile(QIODevice *device) const
writer.writeEndElement(); // sheetViews
int idx = d->workbook->drawings().indexOf(d->drawing.get());
d->relationships->addWorksheetRelationship(QStringLiteral("/drawing"), QStringLiteral("../drawings/drawing%1.xml").arg(idx+1));
d->relationships->addWorksheetRelationship(
QStringLiteral("/drawing"), QStringLiteral("../drawings/drawing%1.xml").arg(idx + 1));
writer.writeEmptyElement(QStringLiteral("drawing"));
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(d->relationships->count()));
writer.writeAttribute(QStringLiteral("r:id"),
QStringLiteral("rId%1").arg(d->relationships->count()));
writer.writeEndElement(); // chartsheet
writer.writeEndDocument();

View File

@ -1,14 +1,14 @@
// xlsxcolor.cpp
#include <QDataStream>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>
#include "xlsxcolor_p.h"
#include "xlsxstyles_p.h"
#include "xlsxutility_p.h"
#include <QDataStream>
#include <QDebug>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
QT_BEGIN_NAMESPACE_XLSX
XlsxColor::XlsxColor(const QColor &color)
@ -20,13 +20,11 @@ XlsxColor::XlsxColor(const QColor &color)
XlsxColor::XlsxColor(const QString &theme, const QString &tint)
: val(QStringList() << theme << tint)
{
}
XlsxColor::XlsxColor(int index)
: val(index)
{
}
bool XlsxColor::isRgbColor() const
@ -116,7 +114,6 @@ XlsxColor::operator QVariant() const
return QVariant(cref, this);
}
QColor XlsxColor::fromARGBString(const QString &c)
{
QColor color;
@ -192,5 +189,4 @@ QDebug operator<<(QDebug dbg, const XlsxColor &c)
#endif
QT_END_NAMESPACE_XLSX

View File

@ -1,46 +1,55 @@
// xlsxconditionalformatting.cpp
#include <QtGlobal>
#include "xlsxconditionalformatting.h"
#include "xlsxcellrange.h"
#include "xlsxconditionalformatting_p.h"
#include "xlsxstyles_p.h"
#include "xlsxworksheet.h"
#include <QDebug>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>
#include "xlsxconditionalformatting.h"
#include "xlsxconditionalformatting_p.h"
#include "xlsxworksheet.h"
#include "xlsxcellrange.h"
#include "xlsxstyles_p.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
ConditionalFormattingPrivate::ConditionalFormattingPrivate()
{
ConditionalFormattingPrivate::ConditionalFormattingPrivate() {}
}
ConditionalFormattingPrivate::ConditionalFormattingPrivate(const ConditionalFormattingPrivate &other)
ConditionalFormattingPrivate::ConditionalFormattingPrivate(
const ConditionalFormattingPrivate &other)
: QSharedData(other)
{
}
ConditionalFormattingPrivate::~ConditionalFormattingPrivate()
{
ConditionalFormattingPrivate::~ConditionalFormattingPrivate() {}
}
void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData &cfvo) const
void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer,
const XlsxCfVoData &cfvo) const
{
writer.writeEmptyElement(QStringLiteral("cfvo"));
QString type;
switch (cfvo.type) {
case ConditionalFormatting::VOT_Formula: type=QStringLiteral("formula"); break;
case ConditionalFormatting::VOT_Max: type=QStringLiteral("max"); break;
case ConditionalFormatting::VOT_Min: type=QStringLiteral("min"); break;
case ConditionalFormatting::VOT_Num: type=QStringLiteral("num"); break;
case ConditionalFormatting::VOT_Percent: type=QStringLiteral("percent"); break;
case ConditionalFormatting::VOT_Percentile: type=QStringLiteral("percentile"); break;
default: break;
case ConditionalFormatting::VOT_Formula:
type = QStringLiteral("formula");
break;
case ConditionalFormatting::VOT_Max:
type = QStringLiteral("max");
break;
case ConditionalFormatting::VOT_Min:
type = QStringLiteral("min");
break;
case ConditionalFormatting::VOT_Num:
type = QStringLiteral("num");
break;
case ConditionalFormatting::VOT_Percent:
type = QStringLiteral("percent");
break;
case ConditionalFormatting::VOT_Percentile:
type = QStringLiteral("percentile");
break;
default:
break;
}
writer.writeAttribute(QStringLiteral("type"), type);
writer.writeAttribute(QStringLiteral("val"), cfvo.value);
@ -56,7 +65,6 @@ void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const Xls
* The conditional formatting can be applied to a single cell or ranges of cells.
*/
/*!
\enum ConditionalFormatting::HighlightRuleType
@ -120,7 +128,6 @@ void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const Xls
ConditionalFormatting::ConditionalFormatting()
: d(new ConditionalFormattingPrivate())
{
}
/*!
@ -129,7 +136,6 @@ ConditionalFormatting::ConditionalFormatting()
ConditionalFormatting::ConditionalFormatting(const ConditionalFormatting &other)
: d(other.d)
{
}
/*!
@ -142,20 +148,21 @@ ConditionalFormatting &ConditionalFormatting::operator=(const ConditionalFormatt
return *this;
}
/*!
* Destroy the object.
*/
ConditionalFormatting::~ConditionalFormatting()
{
}
ConditionalFormatting::~ConditionalFormatting() {}
/*!
* Add a hightlight rule with the given \a type, \a formula1, \a formula2,
* \a format and \a stopIfTrue.
* Return false if failed.
*/
bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const QString &formula2, const Format &format, bool stopIfTrue)
bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type,
const QString &formula1,
const QString &formula2,
const Format &format,
bool stopIfTrue)
{
if (format.isEmpty())
return false;
@ -167,34 +174,55 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("cellIs");
QString op;
switch (type) {
case Highlight_Between: op = QStringLiteral("between"); break;
case Highlight_Equal: op = QStringLiteral("equal"); break;
case Highlight_GreaterThan: op = QStringLiteral("greaterThan"); break;
case Highlight_GreaterThanOrEqual: op = QStringLiteral("greaterThanOrEqual"); break;
case Highlight_LessThan: op = QStringLiteral("lessThan"); break;
case Highlight_LessThanOrEqual: op = QStringLiteral("lessThanOrEqual"); break;
case Highlight_NotBetween: op = QStringLiteral("notBetween"); break;
case Highlight_NotEqual: op = QStringLiteral("notEqual"); break;
default: break;
case Highlight_Between:
op = QStringLiteral("between");
break;
case Highlight_Equal:
op = QStringLiteral("equal");
break;
case Highlight_GreaterThan:
op = QStringLiteral("greaterThan");
break;
case Highlight_GreaterThanOrEqual:
op = QStringLiteral("greaterThanOrEqual");
break;
case Highlight_LessThan:
op = QStringLiteral("lessThan");
break;
case Highlight_LessThanOrEqual:
op = QStringLiteral("lessThanOrEqual");
break;
case Highlight_NotBetween:
op = QStringLiteral("notBetween");
break;
case Highlight_NotEqual:
op = QStringLiteral("notEqual");
break;
default:
break;
}
cfRule->attrs[XlsxCfRuleData::A_operator] = op;
} else if (type >= Highlight_ContainsText && type <= Highlight_EndsWith) {
if (type == Highlight_ContainsText) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsText");
cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("containsText");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(SEARCH(\"%1\",%2)))").arg(formula1);
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] =
QStringLiteral("NOT(ISERROR(SEARCH(\"%1\",%2)))").arg(formula1);
} else if (type == Highlight_NotContainsText) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsText");
cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("notContains");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(SEARCH(\"%2\",%1))").arg(formula1);
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] =
QStringLiteral("ISERROR(SEARCH(\"%2\",%1))").arg(formula1);
} else if (type == Highlight_BeginsWith) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("beginsWith");
cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("beginsWith");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEFT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1);
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] =
QStringLiteral("LEFT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1);
} else {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("endsWith");
cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("endsWith");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("RIGHT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1);
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] =
QStringLiteral("RIGHT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1);
}
cfRule->attrs[XlsxCfRuleData::A_text] = formula1;
skipFormula = true;
@ -228,7 +256,8 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const
cfRule->attrs[XlsxCfRuleData::A_bottom] = QStringLiteral("1");
if (type == Highlight_TopPercent || type == Highlight_BottomPercent)
cfRule->attrs[XlsxCfRuleData::A_percent] = QStringLiteral("1");
cfRule->attrs[XlsxCfRuleData::A_rank] = !formula1.isEmpty() ? formula1 : QStringLiteral("10");
cfRule->attrs[XlsxCfRuleData::A_rank] =
!formula1.isEmpty() ? formula1 : QStringLiteral("10");
skipFormula = true;
} else if (type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("aboveAverage");
@ -253,9 +282,11 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const
cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true;
if (!skipFormula) {
if (!formula1.isEmpty())
cfRule->attrs[XlsxCfRuleData::A_formula1] = formula1.startsWith(QLatin1String("=")) ? formula1.mid(1) : formula1;
cfRule->attrs[XlsxCfRuleData::A_formula1] =
formula1.startsWith(QLatin1String("=")) ? formula1.mid(1) : formula1;
if (!formula2.isEmpty())
cfRule->attrs[XlsxCfRuleData::A_formula2] = formula2.startsWith(QLatin1String("=")) ? formula2.mid(1) : formula2;
cfRule->attrs[XlsxCfRuleData::A_formula2] =
formula2.startsWith(QLatin1String("=")) ? formula2.mid(1) : formula2;
}
d->cfRules.append(cfRule);
return true;
@ -266,10 +297,12 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const
*
* Add a hightlight rule with the given \a type \a format and \a stopIfTrue.
*/
bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const Format &format, bool stopIfTrue)
bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type,
const Format &format,
bool stopIfTrue)
{
if ((type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3)
|| (type >= Highlight_Duplicate && type <= Highlight_NoErrors)) {
if ((type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3) ||
(type >= Highlight_Duplicate && type <= Highlight_NoErrors)) {
return addHighlightCellsRule(type, QString(), QString(), format, stopIfTrue);
}
@ -282,7 +315,10 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const
* Add a hightlight rule with the given \a type, \a formula, \a format and \a stopIfTrue.
* Return false if failed.
*/
bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const QString &formula, const Format &format, bool stopIfTrue)
bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type,
const QString &formula,
const Format &format,
bool stopIfTrue)
{
if (type == Highlight_Between || type == Highlight_NotBetween)
return false;
@ -295,7 +331,13 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const
* , \a type2, \a val2, \a showData and \a stopIfTrue.
* Return false if failed.
*/
bool ConditionalFormatting::addDataBarRule(const QColor &color, ValueObjectType type1, const QString &val1, ValueObjectType type2, const QString &val2, bool showData, bool stopIfTrue)
bool ConditionalFormatting::addDataBarRule(const QColor &color,
ValueObjectType type1,
const QString &val1,
ValueObjectType type2,
const QString &val2,
bool showData,
bool stopIfTrue)
{
auto cfRule = std::make_shared<XlsxCfRuleData>();
@ -321,14 +363,17 @@ bool ConditionalFormatting::addDataBarRule(const QColor &color, ValueObjectType
*/
bool ConditionalFormatting::addDataBarRule(const QColor &color, bool showData, bool stopIfTrue)
{
return addDataBarRule(color, VOT_Min, QStringLiteral("0"), VOT_Max, QStringLiteral("0"), showData, stopIfTrue);
return addDataBarRule(
color, VOT_Min, QStringLiteral("0"), VOT_Max, QStringLiteral("0"), showData, stopIfTrue);
}
/*!
* Add a colorScale rule with the given \a minColor, \a maxColor and \a stopIfTrue.
* Return false if failed.
*/
bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue)
bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor,
const QColor &maxColor,
bool stopIfTrue)
{
ValueObjectType type1 = VOT_Min;
ValueObjectType type2 = VOT_Max;
@ -356,7 +401,10 @@ bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor, const QCo
* Add a colorScale rule with the given \a minColor, \a midColor, \a maxColor and \a stopIfTrue.
* Return false if failed.
*/
bool ConditionalFormatting::add3ColorScaleRule(const QColor &minColor, const QColor &midColor, const QColor &maxColor, bool stopIfTrue)
bool ConditionalFormatting::add3ColorScaleRule(const QColor &minColor,
const QColor &midColor,
const QColor &maxColor,
bool stopIfTrue)
{
ValueObjectType type1 = VOT_Min;
ValueObjectType type2 = VOT_Percent;
@ -429,7 +477,9 @@ void ConditionalFormatting::addRange(const CellRange &range)
d->ranges.append(range);
}
bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRuleData *rule, Styles *styles)
bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader,
XlsxCfRuleData *rule,
Styles *styles)
{
Q_ASSERT(reader.name() == QLatin1String("cfRule"));
QXmlStreamAttributes attrs = reader.attributes();
@ -466,7 +516,8 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu
rule->attrs[XlsxCfRuleData::A_text] = attrs.value(QLatin1String("text")).toString();
if (attrs.hasAttribute(QLatin1String("timePeriod")))
rule->attrs[XlsxCfRuleData::A_timePeriod] = attrs.value(QLatin1String("timePeriod")).toString();
rule->attrs[XlsxCfRuleData::A_timePeriod] =
attrs.value(QLatin1String("timePeriod")).toString();
if (attrs.hasAttribute(QLatin1String("rank")))
rule->attrs[XlsxCfRuleData::A_rank] = attrs.value(QLatin1String("rank")).toString();
@ -496,8 +547,8 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu
readCfColorScale(reader, rule);
}
}
if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QStringLiteral("conditionalFormatting")) {
if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QStringLiteral("conditionalFormatting")) {
break;
}
}
@ -527,8 +578,8 @@ bool ConditionalFormattingPrivate::readCfDataBar(QXmlStreamReader &reader, XlsxC
rule->attrs[XlsxCfRuleData::A_color1] = color;
}
}
if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QStringLiteral("dataBar")) {
if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QStringLiteral("dataBar")) {
break;
}
}
@ -563,8 +614,8 @@ bool ConditionalFormattingPrivate::readCfColorScale(QXmlStreamReader &reader, Xl
rule->attrs[XlsxCfRuleData::A_color3] = color;
}
}
if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QStringLiteral("colorScale")) {
if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QStringLiteral("colorScale")) {
break;
}
}
@ -624,13 +675,12 @@ bool ConditionalFormatting::loadFromXml(QXmlStreamReader &reader, Styles *styles
d->cfRules.append(cfRule);
}
}
if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QStringLiteral("conditionalFormatting")) {
if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QStringLiteral("conditionalFormatting")) {
break;
}
}
return true;
}
@ -647,9 +697,11 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
for (int i = 0; i < d->cfRules.size(); ++i) {
const std::shared_ptr<XlsxCfRuleData> &rule = d->cfRules[i];
writer.writeStartElement(QStringLiteral("cfRule"));
writer.writeAttribute(QStringLiteral("type"), rule->attrs[XlsxCfRuleData::A_type].toString());
writer.writeAttribute(QStringLiteral("type"),
rule->attrs[XlsxCfRuleData::A_type].toString());
if (rule->dxfFormat.dxfIndexValid())
writer.writeAttribute(QStringLiteral("dxfId"), QString::number(rule->dxfFormat.dxfIndex()));
writer.writeAttribute(QStringLiteral("dxfId"),
QString::number(rule->dxfFormat.dxfIndex()));
writer.writeAttribute(QStringLiteral("priority"), QString::number(rule->priority));
auto it = rule->attrs.constFind(XlsxCfRuleData::A_stopIfTrue);
@ -719,7 +771,6 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
writer.writeEndElement(); // colorScale
}
it = rule->attrs.constFind(XlsxCfRuleData::A_formula1_temp);
if (it != rule->attrs.constEnd()) {
const auto _ranges = ranges();
@ -727,9 +778,11 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
if (begin != _ranges.end()) {
QString str = begin->toString();
QString startCell = str.mid(0, str.indexOf(u':'));
writer.writeTextElement(QStringLiteral("formula"), it.value().toString().arg(startCell));
writer.writeTextElement(QStringLiteral("formula"),
it.value().toString().arg(startCell));
}
} else if ((it = rule->attrs.constFind(XlsxCfRuleData::A_formula1)) != rule->attrs.constEnd()) {
} else if ((it = rule->attrs.constFind(XlsxCfRuleData::A_formula1)) !=
rule->attrs.constEnd()) {
writer.writeTextElement(QStringLiteral("formula"), it.value().toString());
}

View File

@ -1,13 +1,13 @@
// xlsxcontenttypes.cpp
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QFile>
#include <QMapIterator>
#include "xlsxcontenttypes_p.h"
#include <QBuffer>
#include <QDebug>
#include "xlsxcontenttypes_p.h"
#include <QFile>
#include <QMapIterator>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
QT_BEGIN_NAMESPACE_XLSX
@ -17,7 +17,8 @@ ContentTypes::ContentTypes(CreateFlag flag)
m_package_prefix = QStringLiteral("application/vnd.openxmlformats-package.");
m_document_prefix = QStringLiteral("application/vnd.openxmlformats-officedocument.");
m_defaults.insert(QStringLiteral("rels"), m_package_prefix + QLatin1String("relationships+xml"));
m_defaults.insert(QStringLiteral("rels"),
m_package_prefix + QLatin1String("relationships+xml"));
m_defaults.insert(QStringLiteral("xml"), QStringLiteral("application/xml"));
}
@ -33,67 +34,80 @@ void ContentTypes::addOverride(const QString &key, const QString &value)
void ContentTypes::addDocPropApp()
{
addOverride(QStringLiteral("/docProps/app.xml"), m_document_prefix + QLatin1String("extended-properties+xml"));
addOverride(QStringLiteral("/docProps/app.xml"),
m_document_prefix + QLatin1String("extended-properties+xml"));
}
void ContentTypes::addDocPropCore()
{
addOverride(QStringLiteral("/docProps/core.xml"), m_package_prefix + QLatin1String("core-properties+xml"));
addOverride(QStringLiteral("/docProps/core.xml"),
m_package_prefix + QLatin1String("core-properties+xml"));
}
void ContentTypes::addStyles()
{
addOverride(QStringLiteral("/xl/styles.xml"), m_document_prefix + QLatin1String("spreadsheetml.styles+xml"));
addOverride(QStringLiteral("/xl/styles.xml"),
m_document_prefix + QLatin1String("spreadsheetml.styles+xml"));
}
void ContentTypes::addTheme()
{
addOverride(QStringLiteral("/xl/theme/theme1.xml"), m_document_prefix + QLatin1String("theme+xml"));
addOverride(QStringLiteral("/xl/theme/theme1.xml"),
m_document_prefix + QLatin1String("theme+xml"));
}
void ContentTypes::addWorkbook()
{
addOverride(QStringLiteral("/xl/workbook.xml"), m_document_prefix + QLatin1String("spreadsheetml.sheet.main+xml"));
addOverride(QStringLiteral("/xl/workbook.xml"),
m_document_prefix + QLatin1String("spreadsheetml.sheet.main+xml"));
}
void ContentTypes::addWorksheetName(const QString &name)
{
addOverride(QStringLiteral("/xl/worksheets/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.worksheet+xml"));
addOverride(QStringLiteral("/xl/worksheets/%1.xml").arg(name),
m_document_prefix + QLatin1String("spreadsheetml.worksheet+xml"));
}
void ContentTypes::addChartsheetName(const QString &name)
{
addOverride(QStringLiteral("/xl/chartsheets/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.chartsheet+xml"));
addOverride(QStringLiteral("/xl/chartsheets/%1.xml").arg(name),
m_document_prefix + QLatin1String("spreadsheetml.chartsheet+xml"));
}
void ContentTypes::addDrawingName(const QString &name)
{
addOverride(QStringLiteral("/xl/drawings/%1.xml").arg(name), m_document_prefix + QLatin1String("drawing+xml"));
addOverride(QStringLiteral("/xl/drawings/%1.xml").arg(name),
m_document_prefix + QLatin1String("drawing+xml"));
}
void ContentTypes::addChartName(const QString &name)
{
addOverride(QStringLiteral("/xl/charts/%1.xml").arg(name), m_document_prefix + QLatin1String("drawingml.chart+xml"));
addOverride(QStringLiteral("/xl/charts/%1.xml").arg(name),
m_document_prefix + QLatin1String("drawingml.chart+xml"));
}
void ContentTypes::addCommentName(const QString &name)
{
addOverride(QStringLiteral("/xl/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.comments+xml"));
addOverride(QStringLiteral("/xl/%1.xml").arg(name),
m_document_prefix + QLatin1String("spreadsheetml.comments+xml"));
}
void ContentTypes::addTableName(const QString &name)
{
addOverride(QStringLiteral("/xl/tables/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.table+xml"));
addOverride(QStringLiteral("/xl/tables/%1.xml").arg(name),
m_document_prefix + QLatin1String("spreadsheetml.table+xml"));
}
void ContentTypes::addExternalLinkName(const QString &name)
{
addOverride(QStringLiteral("/xl/externalLinks/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.externalLink+xml"));
addOverride(QStringLiteral("/xl/externalLinks/%1.xml").arg(name),
m_document_prefix + QLatin1String("spreadsheetml.externalLink+xml"));
}
void ContentTypes::addSharedString()
{
addOverride(QStringLiteral("/xl/sharedStrings.xml"), m_document_prefix + QLatin1String("spreadsheetml.sharedStrings+xml"));
addOverride(QStringLiteral("/xl/sharedStrings.xml"),
m_document_prefix + QLatin1String("spreadsheetml.sharedStrings+xml"));
}
void ContentTypes::addVmlName()
@ -103,7 +117,8 @@ void ContentTypes::addVmlName()
void ContentTypes::addCalcChain()
{
addOverride(QStringLiteral("/xl/calcChain.xml"), m_document_prefix + QLatin1String("spreadsheetml.calcChain+xml"));
addOverride(QStringLiteral("/xl/calcChain.xml"),
m_document_prefix + QLatin1String("spreadsheetml.calcChain+xml"));
}
void ContentTypes::addVbaProject()
@ -123,7 +138,9 @@ void ContentTypes::saveToXmlFile(QIODevice *device) const
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("Types"));
writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("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);
@ -149,7 +166,6 @@ void ContentTypes::saveToXmlFile(QIODevice *device) const
writer.writeEndElement(); // Types
writer.writeEndDocument();
}
bool ContentTypes::loadFromXmlFile(QIODevice *device)

View File

@ -1,45 +1,55 @@
// xlsxdatavalidation.cpp
#include <QtGlobal>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xlsxdatavalidation.h"
#include "xlsxcellrange.h"
#include "xlsxdatavalidation_p.h"
#include "xlsxworksheet.h"
#include "xlsxcellrange.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
DataValidationPrivate::DataValidationPrivate()
:validationType(DataValidation::None), validationOperator(DataValidation::Between)
, errorStyle(DataValidation::Stop), allowBlank(false), isPromptMessageVisible(true)
: validationType(DataValidation::None)
, validationOperator(DataValidation::Between)
, errorStyle(DataValidation::Stop)
, allowBlank(false)
, isPromptMessageVisible(true)
, isErrorMessageVisible(true)
{
}
DataValidationPrivate::DataValidationPrivate(DataValidation::ValidationType type, DataValidation::ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank)
:validationType(type), validationOperator(op)
, errorStyle(DataValidation::Stop), allowBlank(allowBlank), isPromptMessageVisible(true)
, isErrorMessageVisible(true), formula1(formula1), formula2(formula2)
DataValidationPrivate::DataValidationPrivate(DataValidation::ValidationType type,
DataValidation::ValidationOperator op,
const QString &formula1,
const QString &formula2,
bool allowBlank)
: validationType(type)
, validationOperator(op)
, errorStyle(DataValidation::Stop)
, allowBlank(allowBlank)
, isPromptMessageVisible(true)
, isErrorMessageVisible(true)
, formula1(formula1)
, formula2(formula2)
{
}
DataValidationPrivate::DataValidationPrivate(const DataValidationPrivate &other)
: QSharedData(other)
, validationType(DataValidation::None), validationOperator(DataValidation::Between)
, errorStyle(DataValidation::Stop), allowBlank(false), isPromptMessageVisible(true)
, validationType(DataValidation::None)
, validationOperator(DataValidation::Between)
, errorStyle(DataValidation::Stop)
, allowBlank(false)
, isPromptMessageVisible(true)
, isErrorMessageVisible(true)
{
}
DataValidationPrivate::~DataValidationPrivate()
{
}
DataValidationPrivate::~DataValidationPrivate() {}
/*!
* \class DataValidation
@ -61,7 +71,8 @@ DataValidationPrivate::~DataValidationPrivate()
* \value Date restricts the cell to date values.
* \value Time restricts the cell to time values.
* \value TextLength restricts the cell data based on an integer string length.
* \value Custom restricts the cell based on an external Excel formula that returns a true/false value.
* \value Custom restricts the cell based on an external Excel formula that returns a true/false
* value.
*/
/*!
@ -95,10 +106,13 @@ DataValidationPrivate::~DataValidationPrivate()
* Construct a data validation object with the given \a type, \a op, \a formula1
* \a formula2, and \a allowBlank.
*/
DataValidation::DataValidation(ValidationType type, ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank)
DataValidation::DataValidation(ValidationType type,
ValidationOperator op,
const QString &formula1,
const QString &formula2,
bool allowBlank)
: d(new DataValidationPrivate(type, op, formula1, formula2, allowBlank))
{
}
/*!
@ -107,7 +121,6 @@ DataValidation::DataValidation(ValidationType type, ValidationOperator op, const
DataValidation::DataValidation()
: d(new DataValidationPrivate())
{
}
/*!
@ -116,7 +129,6 @@ DataValidation::DataValidation()
DataValidation::DataValidation(const DataValidation &other)
: d(other.d)
{
}
/*!
@ -128,13 +140,10 @@ DataValidation &DataValidation::operator=(const DataValidation &other)
return *this;
}
/*!
* Destroy the object.
*/
DataValidation::~DataValidation()
{
}
DataValidation::~DataValidation() {}
/*!
Returns the validation type.
@ -376,8 +385,7 @@ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const
{DataValidation::Date, QStringLiteral("date")},
{DataValidation::Time, QStringLiteral("time")},
{DataValidation::TextLength, QStringLiteral("textLength")},
{DataValidation::Custom, QStringLiteral("custom")}
};
{DataValidation::Custom, QStringLiteral("custom")}};
static const QMap<DataValidation::ValidationOperator, QString> opMap = {
{DataValidation::Between, QStringLiteral("between")},
@ -387,14 +395,12 @@ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const
{DataValidation::LessThan, QStringLiteral("lessThan")},
{DataValidation::LessThanOrEqual, QStringLiteral("lessThanOrEqual")},
{DataValidation::GreaterThan, QStringLiteral("greaterThan")},
{DataValidation::GreaterThanOrEqual, QStringLiteral("greaterThanOrEqual")}
};
{DataValidation::GreaterThanOrEqual, QStringLiteral("greaterThanOrEqual")}};
static const QMap<DataValidation::ErrorStyle, QString> esMap = {
{DataValidation::Stop, QStringLiteral("stop")},
{DataValidation::Warning, QStringLiteral("warning")},
{DataValidation::Information, QStringLiteral("information")}
};
{DataValidation::Information, QStringLiteral("information")}};
writer.writeStartElement(QStringLiteral("dataValidation"));
if (validationType() != DataValidation::None)
@ -451,8 +457,7 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader)
{QStringLiteral("date"), DataValidation::Date},
{QStringLiteral("time"), DataValidation::Time},
{QStringLiteral("textLength"), DataValidation::TextLength},
{QStringLiteral("custom"), DataValidation::Custom}
};
{QStringLiteral("custom"), DataValidation::Custom}};
static const QMap<QString, DataValidation::ValidationOperator> opMap = {
{QStringLiteral("between"), DataValidation::Between},
@ -462,14 +467,12 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader)
{QStringLiteral("lessThan"), DataValidation::LessThan},
{QStringLiteral("lessThanOrEqual"), DataValidation::LessThanOrEqual},
{QStringLiteral("greaterThan"), DataValidation::GreaterThan},
{QStringLiteral("greaterThanOrEqual"), DataValidation::GreaterThanOrEqual}
};
{QStringLiteral("greaterThanOrEqual"), DataValidation::GreaterThanOrEqual}};
static const QMap<QString, DataValidation::ErrorStyle> esMap = {
{QStringLiteral("stop"), DataValidation::Stop},
{QStringLiteral("warning"), DataValidation::Warning},
{QStringLiteral("information"), DataValidation::Information}
};
{QStringLiteral("information"), DataValidation::Information}};
DataValidation validation;
QXmlStreamAttributes attrs = reader.attributes();
@ -492,7 +495,8 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader)
if (attrs.hasAttribute(QLatin1String("operator"))) {
QString op = attrs.value(QLatin1String("operator")).toString();
auto it = opMap.constFind(op);
validation.setValidationOperator(it != opMap.constEnd() ? it.value() : DataValidation::Between);
validation.setValidationOperator(it != opMap.constEnd() ? it.value()
: DataValidation::Between);
}
if (attrs.hasAttribute(QLatin1String("allowBlank"))) {
validation.setAllowBlank(true);
@ -521,7 +525,8 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader)
validation.setPromptMessage(p, pt);
// find the end
while(!(reader.name() == QLatin1String("dataValidation") && reader.tokenType() == QXmlStreamReader::EndElement)) {
while (!(reader.name() == QLatin1String("dataValidation") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("formula1")) {

View File

@ -1,16 +1,15 @@
// xlsxdatetype.cpp
#include <QtGlobal>
#include "xlsxdatetype.h"
#include "xlsxglobal.h"
#include "xlsxutility_p.h"
#include "xlsxdatetype.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
DateType::DateType()
{
}
DateType::DateType() {}
/*
DateType::DateType(bool is1904)

View File

@ -2,13 +2,13 @@
#include "xlsxdocpropsapp_p.h"
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QBuffer>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QDateTime>
#include <QVariant>
#include <QBuffer>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
QT_BEGIN_NAMESPACE_XLSX
@ -29,9 +29,7 @@ void DocPropsApp::addHeadingPair(const QString &name, int value)
bool DocPropsApp::setProperty(const QString &name, const QString &value)
{
static const QStringList validKeys = {
QStringLiteral("manager"), QStringLiteral("company")
};
static const QStringList validKeys = {QStringLiteral("manager"), QStringLiteral("company")};
if (!validKeys.contains(name))
return false;
@ -61,11 +59,13 @@ QStringList DocPropsApp::propertyNames() const
void DocPropsApp::saveToXmlFile(QIODevice *device) const
{
QXmlStreamWriter writer(device);
QString vt = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
QString vt =
QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("Properties"));
writer.writeDefaultNamespace(QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
writer.writeDefaultNamespace(QStringLiteral(
"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
writer.writeNamespace(vt, QStringLiteral("vt"));
writer.writeTextElement(QStringLiteral("Application"), QStringLiteral("Microsoft Excel"));
writer.writeTextElement(QStringLiteral("DocSecurity"), QStringLiteral("0"));
@ -102,7 +102,8 @@ void DocPropsApp::saveToXmlFile(QIODevice *device) const
// Not like "manager", "company" always exists for Excel generated file.
it = m_properties.constFind(QStringLiteral("company"));
writer.writeTextElement(QStringLiteral("Company"), it != m_properties.constEnd() ? it.value() : QString());
writer.writeTextElement(QStringLiteral("Company"),
it != m_properties.constEnd() ? it.value() : QString());
writer.writeTextElement(QStringLiteral("LinksUpToDate"), QStringLiteral("false"));
writer.writeTextElement(QStringLiteral("SharedDoc"), QStringLiteral("false"));
writer.writeTextElement(QStringLiteral("HyperlinksChanged"), QStringLiteral("false"));

View File

@ -1,15 +1,15 @@
// xlsxdocpropscore.cpp
#include <QtGlobal>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QDir>
#include <QFile>
#include "xlsxdocpropscore_p.h"
#include <QBuffer>
#include <QDateTime>
#include <QDebug>
#include <QBuffer>
#include "xlsxdocpropscore_p.h"
#include <QDir>
#include <QFile>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -20,12 +20,14 @@ DocPropsCore::DocPropsCore(CreateFlag flag)
bool DocPropsCore::setProperty(const QString &name, const QString &value)
{
static const QStringList validKeys = {
QStringLiteral("title"), QStringLiteral("subject"),
QStringLiteral("keywords"), QStringLiteral("description"),
QStringLiteral("category"), QStringLiteral("status"),
QStringLiteral("created"), QStringLiteral("creator")
};
static const QStringList validKeys = {QStringLiteral("title"),
QStringLiteral("subject"),
QStringLiteral("keywords"),
QStringLiteral("description"),
QStringLiteral("category"),
QStringLiteral("status"),
QStringLiteral("created"),
QStringLiteral("creator")};
if (!validKeys.contains(name))
return false;
@ -55,7 +57,8 @@ QStringList DocPropsCore::propertyNames() const
void DocPropsCore::saveToXmlFile(QIODevice *device) const
{
QXmlStreamWriter writer(device);
const QString cp = QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
const QString cp =
QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/");
const QString dcterms = QStringLiteral("http://purl.org/dc/terms/");
const QString dcmitype = QStringLiteral("http://purl.org/dc/dcmitype/");
@ -77,7 +80,10 @@ void DocPropsCore::saveToXmlFile(QIODevice *device) const
writer.writeTextElement(dc, QStringLiteral("subject"), it.value());
it = m_properties.constFind(QStringLiteral("creator"));
writer.writeTextElement(dc, QStringLiteral("creator"), it != m_properties.constEnd() ? it.value() : QStringLiteral("Qt Xlsx Library"));
writer.writeTextElement(dc,
QStringLiteral("creator"),
it != m_properties.constEnd() ? it.value()
: QStringLiteral("Qt Xlsx Library"));
it = m_properties.constFind(QStringLiteral("keywords"));
if (it != m_properties.constEnd())
@ -88,12 +94,17 @@ void DocPropsCore::saveToXmlFile(QIODevice *device) const
writer.writeTextElement(dc, QStringLiteral("description"), it.value());
it = m_properties.constFind(QStringLiteral("creator"));
writer.writeTextElement(cp, QStringLiteral("lastModifiedBy"), it != m_properties.constEnd() ? it.value() : QStringLiteral("Qt Xlsx Library"));
writer.writeTextElement(cp,
QStringLiteral("lastModifiedBy"),
it != m_properties.constEnd() ? it.value()
: QStringLiteral("Qt Xlsx Library"));
writer.writeStartElement(dcterms, QStringLiteral("created"));
writer.writeAttribute(xsi, QStringLiteral("type"), QStringLiteral("dcterms:W3CDTF"));
it = m_properties.constFind(QStringLiteral("created"));
writer.writeCharacters(it != m_properties.constEnd() ? it.value() : QDateTime::currentDateTime().toString(Qt::ISODate));
writer.writeCharacters(it != m_properties.constEnd()
? it.value()
: QDateTime::currentDateTime().toString(Qt::ISODate));
writer.writeEndElement(); // dcterms:created
writer.writeStartElement(dcterms, QStringLiteral("modified"));
@ -117,56 +128,39 @@ bool DocPropsCore::loadFromXmlFile(QIODevice *device)
{
QXmlStreamReader reader(device);
const QString cp = QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
const QString cp =
QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/");
const QString dcterms = QStringLiteral("http://purl.org/dc/terms/");
while (!reader.atEnd())
{
while (!reader.atEnd()) {
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement)
{
if (token == QXmlStreamReader::StartElement) {
const auto &nsUri = reader.namespaceUri();
const auto &name = reader.name();
if (name == QStringLiteral("subject") && nsUri == dc)
{
if (name == QStringLiteral("subject") && nsUri == dc) {
setProperty(QStringLiteral("subject"), reader.readElementText());
}
else if (name == QStringLiteral("title") && nsUri == dc)
{
} else if (name == QStringLiteral("title") && nsUri == dc) {
setProperty(QStringLiteral("title"), reader.readElementText());
}
else if (name == QStringLiteral("creator") && nsUri == dc)
{
} else if (name == QStringLiteral("creator") && nsUri == dc) {
setProperty(QStringLiteral("creator"), reader.readElementText());
}
else if (name == QStringLiteral("description") && nsUri == dc)
{
} else if (name == QStringLiteral("description") && nsUri == dc) {
setProperty(QStringLiteral("description"), reader.readElementText());
}
else if (name == QStringLiteral("keywords") && nsUri == cp)
{
} else if (name == QStringLiteral("keywords") && nsUri == cp) {
setProperty(QStringLiteral("keywords"), reader.readElementText());
}
else if (name == QStringLiteral("created") && nsUri == dcterms)
{
} else if (name == QStringLiteral("created") && nsUri == dcterms) {
setProperty(QStringLiteral("created"), reader.readElementText());
}
else if (name == QStringLiteral("category") && nsUri == cp)
{
} else if (name == QStringLiteral("category") && nsUri == cp) {
setProperty(QStringLiteral("category"), reader.readElementText());
}
else if (name == QStringLiteral("contentStatus") && nsUri == cp)
{
} else if (name == QStringLiteral("contentStatus") && nsUri == cp) {
setProperty(QStringLiteral("status"), reader.readElementText());
}
}
if (reader.hasError())
{
if (reader.hasError()) {
qDebug() << "Error when read doc props core file." << reader.errorString();
}
}

View File

@ -1,34 +1,34 @@
// xlsxdocument.cpp
#include <QtGlobal>
#include <QFile>
#include <QPointF>
#include <QBuffer>
#include <QDir>
#include <QTemporaryFile>
#include <QFile>
#include <QSharedPointer>
#include <QDebug>
#include "xlsxdocument.h"
#include "xlsxdocument_p.h"
#include "xlsxworkbook.h"
#include "xlsxworksheet.h"
#include "xlsxchart.h"
#include "xlsxcontenttypes_p.h"
#include "xlsxrelationships_p.h"
#include "xlsxstyles_p.h"
#include "xlsxtheme_p.h"
#include "xlsxdocpropsapp_p.h"
#include "xlsxdocpropscore_p.h"
#include "xlsxsharedstrings_p.h"
#include "xlsxutility_p.h"
#include "xlsxworkbook_p.h"
#include "xlsxdocument_p.h"
#include "xlsxdrawing_p.h"
#include "xlsxmediafile_p.h"
#include "xlsxchart.h"
#include "xlsxrelationships_p.h"
#include "xlsxsharedstrings_p.h"
#include "xlsxstyles_p.h"
#include "xlsxtheme_p.h"
#include "xlsxutility_p.h"
#include "xlsxworkbook.h"
#include "xlsxworkbook_p.h"
#include "xlsxworksheet.h"
#include "xlsxzipreader_p.h"
#include "xlsxzipwriter_p.h"
#include <QBuffer>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QPointF>
#include <QSharedPointer>
#include <QTemporaryFile>
#include <QtGlobal>
/*
From Wikipedia: The Open Packaging Conventions (OPC) is a
container-file technology initially created by Microsoft to store
@ -67,7 +67,8 @@
QT_BEGIN_NAMESPACE_XLSX
namespace xlsxDocumentCpp {
std::string copyTag(const std::string &sFrom, const std::string &sTo, const std::string &tag) {
std::string copyTag(const std::string &sFrom, const std::string &sTo, const std::string &tag)
{
const std::string tagToFindStart = "<" + tag;
const std::string tagToFindEnd = "</" + tag;
const std::string tagEnd = "</" + tag + ">";
@ -87,12 +88,10 @@ namespace xlsxDocumentCpp {
if (endPos != std::string::npos) {
sFromData += sFrom.substr(startPos, endPos - startPos) + tagEndTmp;
startIndex = endPos + strlen(tagEndTmp.c_str());
}
else {
} else {
break;
}
}
else {
} else {
break;
}
}
@ -107,7 +106,8 @@ namespace xlsxDocumentCpp {
if (startPos != std::string::npos) {
std::size_t endPos = sOut.find(tagToFindEnd);
std::string tagEndTmp = tagEnd;
if (endPos == std::string::npos) { // second try to find the ending, maybe it is "/>"
if (endPos ==
std::string::npos) { // second try to find the ending, maybe it is "/>"
endPos = sOut.find("/>", startPos);
tagEndTmp = "/>";
}
@ -118,12 +118,10 @@ namespace xlsxDocumentCpp {
endPos += strlen(tagEndTmp.c_str());
std::string stringAfter = sOut.substr(endPos, strlen(sOut.c_str()) - endPos);
sOut = stringBefore + stringAfter;
}
else {
} else {
break;
}
}
else {
} else {
break;
}
}
@ -152,11 +150,12 @@ namespace xlsxDocumentCpp {
return sOut;
}
}
} // namespace xlsxDocumentCpp
DocumentPrivate::DocumentPrivate(Document *p) :
q_ptr(p), defaultPackageName(QStringLiteral("Book1.xlsx")),
isLoad(false)
DocumentPrivate::DocumentPrivate(Document *p)
: q_ptr(p)
, defaultPackageName(QStringLiteral("Book1.xlsx"))
, isLoad(false)
{
}
@ -188,7 +187,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
rootRels.loadFromXmlData(zipReader.fileData(QStringLiteral("_rels/.rels")));
// load core property
QList<XlsxRelationship> rels_core = rootRels.packageRelationships(QStringLiteral("/metadata/core-properties"));
QList<XlsxRelationship> rels_core =
rootRels.packageRelationships(QStringLiteral("/metadata/core-properties"));
if (!rels_core.isEmpty()) {
// Get the core property file name if it exists.
// In normal case, this should be "docProps/core.xml"
@ -202,7 +202,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
}
// load app property
QList<XlsxRelationship> rels_app = rootRels.documentRelationships(QStringLiteral("/extended-properties"));
QList<XlsxRelationship> rels_app =
rootRels.documentRelationships(QStringLiteral("/extended-properties"));
if (!rels_app.isEmpty()) {
// Get the app property file name if it exists.
// In normal case, this should be "docProps/app.xml"
@ -218,7 +219,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
// load workbook now, Get the workbook file path from the root rels file
// In normal case, this should be "xl/workbook.xml"
workbook = QSharedPointer<Workbook>(new Workbook(Workbook::F_LoadFromExists));
QList<XlsxRelationship> rels_xl = rootRels.documentRelationships(QStringLiteral("/officeDocument"));
QList<XlsxRelationship> rels_xl =
rootRels.documentRelationships(QStringLiteral("/officeDocument"));
if (rels_xl.isEmpty())
return false;
const QString xlworkbook_Path = rels_xl[0].target;
@ -231,7 +233,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
workbook->loadFromXmlData(zipReader.fileData(xlworkbook_Path));
// load styles
QList<XlsxRelationship> rels_styles = workbook->relationships()->documentRelationships(QStringLiteral("/styles"));
QList<XlsxRelationship> rels_styles =
workbook->relationships()->documentRelationships(QStringLiteral("/styles"));
if (!rels_styles.isEmpty()) {
// In normal case this should be styles.xml which in xl
QString name = rels_styles[0].target;
@ -241,9 +244,7 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
if (xlworkbook_Dir == QLatin1String(".")) // root
{
path = name;
}
else
{
} else {
path = xlworkbook_Dir + QLatin1String("/") + name;
}
@ -253,7 +254,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
}
// load sharedStrings
QList<XlsxRelationship> rels_sharedStrings = workbook->relationships()->documentRelationships(QStringLiteral("/sharedStrings"));
QList<XlsxRelationship> rels_sharedStrings =
workbook->relationships()->documentRelationships(QStringLiteral("/sharedStrings"));
if (!rels_sharedStrings.isEmpty()) {
// In normal case this should be sharedStrings.xml which in xl
QString name = rels_sharedStrings[0].target;
@ -262,7 +264,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
}
// load theme
QList<XlsxRelationship> rels_theme = workbook->relationships()->documentRelationships(QStringLiteral("/theme"));
QList<XlsxRelationship> rels_theme =
workbook->relationships()->documentRelationships(QStringLiteral("/theme"));
if (!rels_theme.isEmpty()) {
// In normal case this should be theme/theme1.xml which in xl
QString name = rels_theme[0].target;
@ -333,65 +336,73 @@ bool DocumentPrivate::savePackage(QIODevice *device) const
DocPropsCore docPropsCore(DocPropsCore::F_NewFromScratch);
// save worksheet xml files
QList<QSharedPointer<AbstractSheet> > worksheets = workbook->getSheetsByTypes(AbstractSheet::ST_WorkSheet);
QList<QSharedPointer<AbstractSheet>> worksheets =
workbook->getSheetsByTypes(AbstractSheet::ST_WorkSheet);
if (!worksheets.isEmpty())
docPropsApp.addHeadingPair(QStringLiteral("Worksheets"), worksheets.size());
for (int i = 0 ; i < worksheets.size(); ++i)
{
for (int i = 0; i < worksheets.size(); ++i) {
QSharedPointer<AbstractSheet> sheet = worksheets[i];
contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i + 1));
docPropsApp.addPartTitle(sheet->sheetName());
zipWriter.addFile(QStringLiteral("xl/worksheets/sheet%1.xml").arg(i+1), sheet->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/worksheets/sheet%1.xml").arg(i + 1),
sheet->saveToXmlData());
Relationships *rel = sheet->relationships();
if (!rel->isEmpty())
zipWriter.addFile(QStringLiteral("xl/worksheets/_rels/sheet%1.xml.rels").arg(i+1), rel->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/worksheets/_rels/sheet%1.xml.rels").arg(i + 1),
rel->saveToXmlData());
}
// save chartsheet xml files
QList<QSharedPointer<AbstractSheet> > chartsheets = workbook->getSheetsByTypes(AbstractSheet::ST_ChartSheet);
QList<QSharedPointer<AbstractSheet>> chartsheets =
workbook->getSheetsByTypes(AbstractSheet::ST_ChartSheet);
if (!chartsheets.isEmpty())
docPropsApp.addHeadingPair(QStringLiteral("Chartsheets"), chartsheets.size());
for (int i=0; i<chartsheets.size(); ++i)
{
for (int i = 0; i < chartsheets.size(); ++i) {
QSharedPointer<AbstractSheet> sheet = chartsheets[i];
contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i + 1));
docPropsApp.addPartTitle(sheet->sheetName());
zipWriter.addFile(QStringLiteral("xl/chartsheets/sheet%1.xml").arg(i+1), sheet->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/chartsheets/sheet%1.xml").arg(i + 1),
sheet->saveToXmlData());
Relationships *rel = sheet->relationships();
if (!rel->isEmpty())
zipWriter.addFile(QStringLiteral("xl/chartsheets/_rels/sheet%1.xml.rels").arg(i+1), rel->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/chartsheets/_rels/sheet%1.xml.rels").arg(i + 1),
rel->saveToXmlData());
}
// save external links xml files
for (int i=0; i<workbook->d_func()->externalLinks.count(); ++i)
{
for (int i = 0; i < workbook->d_func()->externalLinks.count(); ++i) {
SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data();
contentTypes->addExternalLinkName(QStringLiteral("externalLink%1").arg(i + 1));
zipWriter.addFile(QStringLiteral("xl/externalLinks/externalLink%1.xml").arg(i+1), link->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/externalLinks/externalLink%1.xml").arg(i + 1),
link->saveToXmlData());
Relationships *rel = link->relationships();
if (!rel->isEmpty())
zipWriter.addFile(QStringLiteral("xl/externalLinks/_rels/externalLink%1.xml.rels").arg(i+1), rel->saveToXmlData());
zipWriter.addFile(
QStringLiteral("xl/externalLinks/_rels/externalLink%1.xml.rels").arg(i + 1),
rel->saveToXmlData());
}
// save workbook xml file
contentTypes->addWorkbook();
zipWriter.addFile(QStringLiteral("xl/workbook.xml"), workbook->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/_rels/workbook.xml.rels"), workbook->relationships()->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/_rels/workbook.xml.rels"),
workbook->relationships()->saveToXmlData());
// save drawing xml files
for (int i=0; i<workbook->drawings().size(); ++i)
{
for (int i = 0; i < workbook->drawings().size(); ++i) {
contentTypes->addDrawingName(QStringLiteral("drawing%1").arg(i + 1));
Drawing *drawing = workbook->drawings()[i];
zipWriter.addFile(QStringLiteral("xl/drawings/drawing%1.xml").arg(i+1), drawing->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/drawings/drawing%1.xml").arg(i + 1),
drawing->saveToXmlData());
if (!drawing->relationships()->isEmpty())
zipWriter.addFile(QStringLiteral("xl/drawings/_rels/drawing%1.xml.rels").arg(i+1), drawing->relationships()->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/drawings/_rels/drawing%1.xml.rels").arg(i + 1),
drawing->relationships()->saveToXmlData());
}
// save docProps app/core xml file
@ -408,7 +419,8 @@ bool DocumentPrivate::savePackage(QIODevice *device) const
// save sharedStrings xml file
if (!workbook->sharedStrings()->isEmpty()) {
contentTypes->addSharedString();
zipWriter.addFile(QStringLiteral("xl/sharedStrings.xml"), workbook->sharedStrings()->saveToXmlData());
zipWriter.addFile(QStringLiteral("xl/sharedStrings.xml"),
workbook->sharedStrings()->saveToXmlData());
}
// save calc chain [dev16]
@ -424,8 +436,7 @@ bool DocumentPrivate::savePackage(QIODevice *device) const
zipWriter.addFile(QStringLiteral("xl/theme/theme1.xml"), workbook->theme()->saveToXmlData());
// save chart xml files
for (int i=0; i<workbook->chartFiles().size(); ++i)
{
for (int i = 0; i < workbook->chartFiles().size(); ++i) {
contentTypes->addChartName(QStringLiteral("chart%1").arg(i + 1));
QSharedPointer<Chart> cf = workbook->chartFiles()[i];
zipWriter.addFile(QStringLiteral("xl/charts/chart%1.xml").arg(i + 1), cf->saveToXmlData());
@ -433,20 +444,23 @@ bool DocumentPrivate::savePackage(QIODevice *device) const
// save image files
const auto mfs = workbook->mediaFiles();
for (int i=0; i < mfs.size(); ++i)
{
for (int i = 0; i < mfs.size(); ++i) {
auto mf = mfs[i];
if (!mf->mimeType().isEmpty())
contentTypes->addDefault(mf->suffix(), mf->mimeType());
zipWriter.addFile(QStringLiteral("xl/media/image%1.%2").arg(i+1).arg(mf->suffix()), mf->contents());
zipWriter.addFile(QStringLiteral("xl/media/image%1.%2").arg(i + 1).arg(mf->suffix()),
mf->contents());
}
// save root .rels xml file
Relationships rootrels;
rootrels.addDocumentRelationship(QStringLiteral("/officeDocument"), QStringLiteral("xl/workbook.xml"));
rootrels.addPackageRelationship(QStringLiteral("/metadata/core-properties"), QStringLiteral("docProps/core.xml"));
rootrels.addDocumentRelationship(QStringLiteral("/extended-properties"), QStringLiteral("docProps/app.xml"));
rootrels.addDocumentRelationship(QStringLiteral("/officeDocument"),
QStringLiteral("xl/workbook.xml"));
rootrels.addPackageRelationship(QStringLiteral("/metadata/core-properties"),
QStringLiteral("docProps/core.xml"));
rootrels.addDocumentRelationship(QStringLiteral("/extended-properties"),
QStringLiteral("docProps/app.xml"));
zipWriter.addFile(QStringLiteral("_rels/.rels"), rootrels.saveToXmlData());
// save content types xml file
@ -478,8 +492,10 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to)
if (toFilePaths[i].contains(QLatin1String("xl/styles"))) {
if (filePaths.contains(toFilePaths[i])) { // style file exist in 'from' as well
// modify style file
std::string fromData = QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString();
std::string toData = QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString();
std::string fromData =
QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString();
std::string toData =
QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString();
// copy default theme style from 'from' to 'to'
toData = xlsxDocumentCpp::copyTag(fromData, toData, "dxfs");
temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8());
@ -491,8 +507,10 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to)
if (toFilePaths[i].contains(QLatin1String("xl/workbook"))) {
if (filePaths.contains(toFilePaths[i])) { // workbook file exist in 'from' as well
// modify workbook file
std::string fromData = QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString();
std::string toData = QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString();
std::string fromData =
QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString();
std::string toData =
QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString();
// copy default theme style from 'from' to 'to'
toData = xlsxDocumentCpp::copyTag(fromData, toData, "workbookPr");
temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8());
@ -503,8 +521,10 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to)
if (toFilePaths[i].contains(QLatin1String("xl/worksheets/sheet"))) {
if (filePaths.contains(toFilePaths[i])) { // sheet file exist in 'from' as well
// modify sheet file
std::string fromData = QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString();
std::string toData = QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString();
std::string fromData =
QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString();
std::string toData =
QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString();
// copy "conditionalFormatting" from 'from' to 'to'
toData = xlsxDocumentCpp::copyTag(fromData, toData, "conditionalFormatting");
temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8());
@ -539,8 +559,9 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to)
* Creates a new empty xlsx document.
* The \a parent argument is passed to QObject's constructor.
*/
Document::Document(QObject *parent) :
QObject(parent), d_ptr(new DocumentPrivate(this))
Document::Document(QObject *parent)
: QObject(parent)
, d_ptr(new DocumentPrivate(this))
{
d_ptr->init();
}
@ -550,20 +571,16 @@ Document::Document(QObject *parent) :
* Try to open an existing xlsx document named \a name.
* The \a parent argument is passed to QObject's constructor.
*/
Document::Document(const QString &name,
QObject *parent) :
QObject(parent),
d_ptr(new DocumentPrivate(this))
Document::Document(const QString &name, QObject *parent)
: QObject(parent)
, d_ptr(new DocumentPrivate(this))
{
d_ptr->packageName = name;
if (QFile::exists(name))
{
if (QFile::exists(name)) {
QFile xlsx(name);
if (xlsx.open(QFile::ReadOnly))
{
if (! d_ptr->loadPackage(&xlsx))
{
if (xlsx.open(QFile::ReadOnly)) {
if (!d_ptr->loadPackage(&xlsx)) {
// NOTICE: failed to load package
}
}
@ -577,13 +594,12 @@ Document::Document(const QString &name,
* Try to open an existing xlsx document from \a device.
* The \a parent argument is passed to QObject's constructor.
*/
Document::Document(QIODevice *device, QObject *parent) :
QObject(parent), d_ptr(new DocumentPrivate(this))
{
if (device && device->isReadable())
{
if (!d_ptr->loadPackage(device))
Document::Document(QIODevice *device, QObject *parent)
: QObject(parent)
, d_ptr(new DocumentPrivate(this))
{
if (device && device->isReadable()) {
if (!d_ptr->loadPackage(device)) {
// NOTICE: failed to load package
}
}
@ -674,7 +690,6 @@ uint Document::getImageCount()
return 0;
}
/*!
* Creates an chart with the given \a size and insert it to the current
* active worksheet at the position \a row, \a col.
@ -796,7 +811,6 @@ bool Document::setColumnFormat(int colFirst, int colLast, const Format &format)
return false;
}
/*!
Sets hidden property of columns [\a colFirst, \a colLast] to \a hidden.
Columns are 1-indexed.
@ -1023,7 +1037,10 @@ Cell *Document::cellAt(int row, int col) const
* \param scope The name of one worksheet, or empty which means golbal scope.
* \return Return false if the name invalid.
*/
bool Document::defineName(const QString &name, const QString &formula, const QString &comment, const QString &scope)
bool Document::defineName(const QString &name,
const QString &formula,
const QString &comment,
const QString &scope)
{
Q_D(Document);
@ -1272,7 +1289,8 @@ bool Document::load() const
return isLoadPackage();
}
bool Document::copyStyle(const QString &from, const QString &to) {
bool Document::copyStyle(const QString &from, const QString &to)
{
return DocumentPrivate::copyStyle(from, to);
}
@ -1318,7 +1336,6 @@ bool Document::changeimage(int filenoinmidea, QString newfile)
}
// liufeijin }}
/*!
Returns map of columns with there maximal width
*/
@ -1328,28 +1345,26 @@ QMap<int, int> Document::getMaximalColumnWidth(int firstRow, int lastRow)
int maxRows = -1;
int maxCols = -1;
QMap<int, int> colWidth;
if (!currentWorksheet()) return colWidth;
if (!currentWorksheet())
return colWidth;
QVector<CellLocation> cellLocation = currentWorksheet()->getFullCells(&maxRows, &maxCols);
for(int i=0; i < cellLocation.size(); i++)
{
for (int i = 0; i < cellLocation.size(); i++) {
int col = cellLocation.at(i).col;
int row = cellLocation.at(i).row;
int fs = cellLocation.at(i).cell->format().fontSize();
if( fs <= 0)
{
if (fs <= 0) {
fs = defaultPixelSize;
}
// QString str = cellLocation.at(i).cell.data()->value().toString();
QString str = read(row, col).toString();
double w = str.length() * double(fs) / defaultPixelSize + 1; // width not perfect, but works reasonably well
double w = str.length() * double(fs) / defaultPixelSize +
1; // width not perfect, but works reasonably well
if( (row >= firstRow) && (row <= lastRow))
{
if( w > colWidth.value(col))
{
if ((row >= firstRow) && (row <= lastRow)) {
if (w > colWidth.value(col)) {
colWidth.insert(col, int(w));
}
}
@ -1358,7 +1373,6 @@ QMap<int, int> Document::getMaximalColumnWidth(int firstRow, int lastRow)
return colWidth;
}
/*!
Auto ets width in characters of columns with the given \a range.
Returns true on success.
@ -1367,16 +1381,14 @@ bool Document::autosizeColumnWidth(const CellRange &range)
{
bool erg = false;
if( !range.isValid())
{
if (!range.isValid()) {
return false;
}
const QMap<int, int> colWidth = getMaximalColumnWidth(range.firstRow(), range.lastRow());
auto it = colWidth.constBegin();
while (it != colWidth.constEnd()) {
if( (it.key() >= range.firstColumn()) && (it.key() <= range.lastColumn()) )
{
if ((it.key() >= range.firstColumn()) && (it.key() <= range.lastColumn())) {
erg |= setColumnWidth(it.key(), it.value());
}
++it;
@ -1385,7 +1397,6 @@ bool Document::autosizeColumnWidth(const CellRange &range)
return erg;
}
/*!
Auto sets width in characters \a column . Columns are 1-indexed.
Returns true on success.
@ -1397,8 +1408,7 @@ bool Document::autosizeColumnWidth(int column)
const QMap<int, int> colWidth = getMaximalColumnWidth();
auto it = colWidth.constBegin();
while (it != colWidth.constEnd()) {
if( it.key() == column)
{
if (it.key() == column) {
erg |= setColumnWidth(it.key(), it.value());
}
++it;
@ -1407,7 +1417,6 @@ bool Document::autosizeColumnWidth(int column)
return erg;
}
/*!
Auto sets width in characters for columns [\a colFirst, \a colLast]. Columns are 1-indexed.
Returns true on success.
@ -1421,8 +1430,7 @@ bool Document::autosizeColumnWidth(int colFirst, int colLast)
const QMap<int, int> colWidth = getMaximalColumnWidth();
auto it = colWidth.constBegin();
while (it != colWidth.constEnd()) {
if( (it.key() >= colFirst) && (it.key() <= colLast) )
{
if ((it.key() >= colFirst) && (it.key() <= colLast)) {
erg |= setColumnWidth(it.key(), it.value());
}
++it;
@ -1431,7 +1439,6 @@ bool Document::autosizeColumnWidth(int colFirst, int colLast)
return erg;
}
/*!
Auto sets width in characters for all columns.
Returns true on success.
@ -1450,5 +1457,4 @@ bool Document::autosizeColumnWidth(void)
return erg;
}
QT_END_NAMESPACE_XLSX

View File

@ -1,18 +1,19 @@
// xlsxdrawing.cpp
#include <QtGlobal>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QBuffer>
#include "xlsxabstractsheet.h"
#include "xlsxdrawing_p.h"
#include "xlsxdrawinganchor_p.h"
#include "xlsxabstractsheet.h"
#include <QBuffer>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
Drawing::Drawing(AbstractSheet *sheet, CreateFlag flag)
:AbstractOOXmlFile(flag), sheet(sheet)
: AbstractOOXmlFile(flag)
, sheet(sheet)
{
workbook = sheet->workbook();
}
@ -30,8 +31,11 @@ void Drawing::saveToXmlFile(QIODevice *device) const
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("xdr:wsDr"));
writer.writeAttribute(QStringLiteral("xmlns:xdr"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"));
writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main"));
writer.writeAttribute(
QStringLiteral("xmlns:xdr"),
QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"));
writer.writeAttribute(QStringLiteral("xmlns:a"),
QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main"));
for (DrawingAnchor *anchor : anchors)
anchor->saveToXml(writer);
@ -55,22 +59,18 @@ bool Drawing::loadFromXmlFile(QIODevice *device)
QXmlStreamReader reader(device);
while (!reader.atEnd())
{
while (!reader.atEnd()) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement)
{
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("absoluteAnchor")) // CT_AbsoluteAnchor
{
DrawingAbsoluteAnchor *anchor = new DrawingAbsoluteAnchor(this);
anchor->loadFromXml(reader);
}
else if (reader.name() == QLatin1String("oneCellAnchor")) // CT_OneCellAnchor
} else if (reader.name() == QLatin1String("oneCellAnchor")) // CT_OneCellAnchor
{
DrawingOneCellAnchor *anchor = new DrawingOneCellAnchor(this);
anchor->loadFromXml(reader);
}
else if (reader.name() == QLatin1String("twoCellAnchor")) // CT_TwoCellAnchor
} else if (reader.name() == QLatin1String("twoCellAnchor")) // CT_TwoCellAnchor
{
DrawingTwoCellAnchor *anchor = new DrawingTwoCellAnchor(this);
anchor->loadFromXml(reader);

View File

@ -1,18 +1,18 @@
// xlsxdrawinganchor.cpp
#include <QtGlobal>
#include "xlsxchart.h"
#include "xlsxdrawing_p.h"
#include "xlsxdrawinganchor_p.h"
#include "xlsxmediafile_p.h"
#include "xlsxutility_p.h"
#include "xlsxworkbook.h"
#include <QBuffer>
#include <QDebug>
#include <QDir>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QBuffer>
#include <QDir>
#include "xlsxdrawinganchor_p.h"
#include "xlsxdrawing_p.h"
#include "xlsxmediafile_p.h"
#include "xlsxchart.h"
#include "xlsxworkbook.h"
#include "xlsxutility_p.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -50,16 +50,14 @@ QT_BEGIN_NAMESPACE_XLSX
// anchor
DrawingAnchor::DrawingAnchor(Drawing *drawing, ObjectType objectType)
:m_drawing(drawing), m_objectType(objectType)
: m_drawing(drawing)
, m_objectType(objectType)
{
m_drawing->anchors.append(this);
m_id = m_drawing->anchors.size(); // must be unique in one drawing{x}.xml file.
}
DrawingAnchor::~DrawingAnchor()
{
}
DrawingAnchor::~DrawingAnchor() {}
void DrawingAnchor::setObjectPicture(const QImage &img)
{
@ -68,7 +66,8 @@ void DrawingAnchor::setObjectPicture(const QImage &img)
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG");
m_pictureFile = std::make_shared<MediaFile>(ba, QStringLiteral("png"), QStringLiteral("image/png"));
m_pictureFile =
std::make_shared<MediaFile>(ba, QStringLiteral("png"), QStringLiteral("image/png"));
m_drawing->workbook->addMediaFile(m_pictureFile);
m_objectType = Picture;
@ -91,7 +90,8 @@ void DrawingAnchor::setObjectShape(const QImage &img)
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG");
m_pictureFile = std::make_shared<MediaFile>(ba, QStringLiteral("png"), QStringLiteral("image/png"));
m_pictureFile =
std::make_shared<MediaFile>(ba, QStringLiteral("png"), QStringLiteral("image/png"));
m_drawing->workbook->addMediaFile(m_pictureFile);
m_objectType = Shape;
@ -146,31 +146,19 @@ XlsxMarker DrawingAnchor::loadXmlMarker(QXmlStreamReader &reader, const QString
int colOffset = 0;
int row = 0;
int rowOffset = 0;
while (!reader.atEnd())
{
while (!reader.atEnd()) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement)
{
if (reader.name() == QLatin1String("col"))
{
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("col")) {
col = reader.readElementText().toInt();
}
else if (reader.name() == QLatin1String("colOff"))
{
} else if (reader.name() == QLatin1String("colOff")) {
colOffset = reader.readElementText().toInt();
}
else if (reader.name() == QLatin1String("row"))
{
} else if (reader.name() == QLatin1String("row")) {
row = reader.readElementText().toInt();
}
else if (reader.name() == QLatin1String("rowOff"))
{
} else if (reader.name() == QLatin1String("rowOff")) {
rowOffset = reader.readElementText().toInt();
}
}
else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == node)
{
} else if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == node) {
break;
}
}
@ -211,20 +199,20 @@ void DrawingAnchor::loadXmlObject(QXmlStreamReader &reader)
// <xsd:attribute name="fPublished" type="xsd:boolean" use="optional" default="false"/>
loadXmlObjectShape(reader); // CT_Shape
}
else if (reader.name() == QLatin1String("grpSp")) // <xsd:element name="grpSp" type="CT_GroupShape"/>
} else if (reader.name() ==
QLatin1String("grpSp")) // <xsd:element name="grpSp" type="CT_GroupShape"/>
{
// Group Shape
m_objectType = GroupShape;
loadXmlObjectGroupShape(reader);
}
else if (reader.name() == QLatin1String("graphicFrame")) // <xsd:element name="graphicFrame" type="CT_GraphicalObjectFrame"/>
} else if (reader.name() == QLatin1String("graphicFrame")) // <xsd:element name="graphicFrame"
// type="CT_GraphicalObjectFrame"/>
{
// Graphic Frame
m_objectType = GraphicFrame;
loadXmlObjectGraphicFrame(reader);
}
else if (reader.name() == QLatin1String("cxnSp")) // <xsd:element name="cxnSp" type="CT_Connector"/>
} else if (reader.name() ==
QLatin1String("cxnSp")) // <xsd:element name="cxnSp" type="CT_Connector"/>
{
// Connection Shape
m_objectType = ConnectionShape;
@ -234,14 +222,13 @@ void DrawingAnchor::loadXmlObject(QXmlStreamReader &reader)
// }}
loadXmlObjectConnectionShape(reader);
}
else if (reader.name() == QLatin1String("pic")) // <xsd:element name="pic" type="CT_Picture"/>
} else if (reader.name() == QLatin1String("pic")) // <xsd:element name="pic" type="CT_Picture"/>
{
// Picture
m_objectType = Picture;
loadXmlObjectPicture(reader);
}
else if (reader.name() == QLatin1String("contentPart")) // <xsd:element name="contentPart" type="CT_Rel"/>
} else if (reader.name() ==
QLatin1String("contentPart")) // <xsd:element name="contentPart" type="CT_Rel"/>
{
// contentPart
/// TODO:
@ -269,7 +256,8 @@ void DrawingAnchor::loadXmlObjectConnectionShape(QXmlStreamReader &reader)
extTA = loadXmlExt(reader);
hasoffext = false;
} else if (reader.name() == QLatin1String("prstGeom")) {
xprstGeom_prst= reader.attributes().value(QLatin1String("prst")).toString().trimmed();
xprstGeom_prst =
reader.attributes().value(QLatin1String("prst")).toString().trimmed();
} else if (reader.name() == QLatin1String("ln")) {
xIn_algn = reader.attributes().value(QLatin1String("algn")).toString().trimmed();
xIn_cmpd = reader.attributes().value(QLatin1String("cmpd")).toString().trimmed();
@ -277,54 +265,65 @@ void DrawingAnchor::loadXmlObjectConnectionShape(QXmlStreamReader &reader)
xIn_w = reader.attributes().value(QLatin1String("w")).toString().trimmed();
} else if (reader.name() == QLatin1String("headEnd")) {
x_headEnd_w = reader.attributes().value(QLatin1String("w")).toString().trimmed();
x_headEnd_len= reader.attributes().value(QLatin1String("len")).toString().trimmed();
x_headEnd_tyep= reader.attributes().value(QLatin1String("type")).toString().trimmed();
x_headEnd_len =
reader.attributes().value(QLatin1String("len")).toString().trimmed();
x_headEnd_tyep =
reader.attributes().value(QLatin1String("type")).toString().trimmed();
} else if (reader.name() == QLatin1String("tailEnd")) {
x_tailEnd_w = reader.attributes().value(QLatin1String("w")).toString().trimmed();
x_tailEnd_len= reader.attributes().value(QLatin1String("len")).toString().trimmed();
x_tailEnd_tyep= reader.attributes().value(QLatin1String("type")).toString().trimmed();
x_tailEnd_len =
reader.attributes().value(QLatin1String("len")).toString().trimmed();
x_tailEnd_tyep =
reader.attributes().value(QLatin1String("type")).toString().trimmed();
} else if (reader.name() == QLatin1String("lnRef")) {
Style_inref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
Style_inref_idx =
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("schemeClr")) {
Style_inref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
Style_inref_val =
reader.attributes().value(QLatin1String("val")).toString().trimmed();
}
}
} else if (reader.name() == QLatin1String("fillRef")) {
style_fillref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
style_fillref_idx =
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("schemeClr")) {
style_fillref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
style_fillref_val =
reader.attributes().value(QLatin1String("val")).toString().trimmed();
}
}
} else if (reader.name() == QLatin1String("effectRef")) {
style_effectref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
style_effectref_idx =
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("schemeClr")) {
style_effectref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
style_effectref_val =
reader.attributes().value(QLatin1String("val")).toString().trimmed();
}
}
} else if (reader.name() == QLatin1String("fontRef")) {
style_forntref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
style_forntref_idx =
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("schemeClr")) {
style_forntref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
style_forntref_val =
reader.attributes().value(QLatin1String("val")).toString().trimmed();
}
}
}
} else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("cxnSp")) {
} else if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("cxnSp")) {
break;
}
}
return;
}
void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader)
@ -351,13 +350,14 @@ void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader)
}
}
if (!exist) {
m_chartFile = QSharedPointer<Chart> (new Chart(m_drawing->sheet, Chart::F_LoadFromExists));
m_chartFile =
QSharedPointer<Chart>(new Chart(m_drawing->sheet, Chart::F_LoadFromExists));
m_chartFile->setFilePath(path);
m_drawing->workbook->addChartFile(m_chartFile);
}
}
} else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("graphicFrame")) {
} else if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("graphicFrame")) {
break;
}
}
@ -398,8 +398,8 @@ void DrawingAnchor::loadXmlObjectPicture(QXmlStreamReader &reader)
m_drawing->workbook->addMediaFile(m_pictureFile, true);
}
}
} else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("pic")) {
} else if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("pic")) {
break;
}
}
@ -427,41 +427,30 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
<xsd:complexType name="CT_ShapeNonVisual">
<xsd:sequence>
<xsd:element name="cNvPr" type="a:CT_NonVisualDrawingProps" minOccurs="1" maxOccurs="1"/>
<xsd:element name="cNvSpPr" type="a:CT_NonVisualDrawingShapeProps" minOccurs="1" maxOccurs="1"/>
<xsd:element name="cNvSpPr" type="a:CT_NonVisualDrawingShapeProps" minOccurs="1"
maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
*/
Q_ASSERT(reader.name() == QLatin1String("sp"));
while (!reader.atEnd())
{
while (!reader.atEnd()) {
reader.readNextStartElement();
// qDebug() << __FUNCTION__ << reader.name().toString();
if (reader.tokenType() == QXmlStreamReader::StartElement)
{
if (reader.name() == QLatin1String("nvSpPr"))
{
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("nvSpPr")) {
}
else if (reader.name() == QLatin1String("spPr"))
{
} else if (reader.name() == QLatin1String("spPr")) {
}
else if (reader.name() == QLatin1String("style"))
{
} else if (reader.name() == QLatin1String("style")) {
} else if (reader.name() == QLatin1String("txBody")) {
}
else if (reader.name() == QLatin1String("txBody"))
{
}
}
else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("sp"))
{
} else if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("sp")) {
break;
}
}
@ -484,10 +473,9 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
sp_blip_cstate=reader.attributes().value(QLatin1String("cstate")).toString();
rId=sp_blip_rembed;
QString name = m_drawing->relationships()->getRelationshipById(rId).target;
QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name);
bool exist = false;
QList<QSharedPointer<MediaFile> > mfs = m_drawing->workbook->mediaFiles();
for (int i=0; i<mfs.size(); ++i)
QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] +
QLatin1String("/") + name); bool exist = false; QList<QSharedPointer<MediaFile> > mfs =
m_drawing->workbook->mediaFiles(); for (int i=0; i<mfs.size(); ++i)
{
if (mfs[i]->fileName() == path)
{
@ -515,10 +503,12 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
{
// dev24 : fixed for old Qt 5
rotWithShapeTA = reader.attributes().value(QLatin1String("rotWithShape")).toString().toInt();
dpiTA = reader.attributes().value(QLatin1String("dpi")).toString().toInt();
rotWithShapeTA =
reader.attributes().value(QLatin1String("rotWithShape")).toString().toInt(); dpiTA =
reader.attributes().value(QLatin1String("dpi")).toString().toInt();
// rotWithShapeTA = reader.attributes().value(QLatin1String("rotWithShape")).toInt();
// rotWithShapeTA =
reader.attributes().value(QLatin1String("rotWithShape")).toInt();
// dpiTA = reader.attributes().value(QLatin1String("dpi")).toInt();
}else if(reader.name() == QLatin1String("cNvPr"))
@ -555,7 +545,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
}
else if(reader.name() == QLatin1String("lnRef"))
{
Style_inref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
Style_inref_idx=
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if(reader.name() == QLatin1String("schemeClr")){
@ -565,7 +556,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
}
else if(reader.name() == QLatin1String("fillRef"))
{
style_fillref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
style_fillref_idx=
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement)
{
@ -577,7 +569,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
}
else if(reader.name() == QLatin1String("effectRef"))
{
style_effectref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
style_effectref_idx=
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if(reader.name() == QLatin1String("schemeClr")){
@ -587,7 +580,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
}
else if(reader.name() == QLatin1String("fontRef"))
{
style_forntref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
style_forntref_idx=
reader.attributes().value(QLatin1String("idx")).toString().trimmed();
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if(reader.name() == QLatin1String("schemeClr")){
@ -624,7 +618,9 @@ void DrawingAnchor::saveXmlExt(QXmlStreamWriter &writer, const QSize &ext) const
writer.writeEndElement(); // xdr:ext
}
void DrawingAnchor::saveXmlMarker(QXmlStreamWriter &writer, const XlsxMarker &marker, const QString &node) const
void DrawingAnchor::saveXmlMarker(QXmlStreamWriter &writer,
const XlsxMarker &marker,
const QString &node) const
{
writer.writeStartElement(node); // xdr:from or xdr:to
writer.writeTextElement(QStringLiteral("xdr:col"), QString::number(marker.col()));
@ -667,7 +663,8 @@ void DrawingAnchor::saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const
writer.writeStartElement(QStringLiteral("a:xfrm"));
if (!cxnSp_filpV.isEmpty()) {
writer.writeAttribute(QStringLiteral("flipV"), cxnSp_filpV);}
writer.writeAttribute(QStringLiteral("flipV"), cxnSp_filpV);
}
writer.writeEmptyElement(QStringLiteral("a:off"));
writer.writeAttribute(QStringLiteral("x"), QString::number(posTA.x()));
writer.writeAttribute(QStringLiteral("y"), QString::number(posTA.y()));
@ -681,7 +678,6 @@ void DrawingAnchor::saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const
writer.writeEmptyElement(QStringLiteral("a:avLst"));
writer.writeEndElement(); // a:prstGeom
writer.writeStartElement(QStringLiteral("a:ln"));
if (!xIn_w.isEmpty() && !xIn_cap.isEmpty()) {
if (!xIn_w.isEmpty()) {
@ -712,16 +708,18 @@ void DrawingAnchor::saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const
if ((!x_tailEnd_tyep.isEmpty()) || (!x_tailEnd_w.isEmpty()) || (!x_tailEnd_len.isEmpty())) {
writer.writeEmptyElement(QStringLiteral("a:tailEnd"));
if (!x_tailEnd_tyep.isEmpty()) {
writer.writeAttribute(QStringLiteral("type"),x_tailEnd_tyep);}
writer.writeAttribute(QStringLiteral("type"), x_tailEnd_tyep);
}
if (!x_tailEnd_w.isEmpty()) {
writer.writeAttribute(QStringLiteral("w"),x_tailEnd_w);}
writer.writeAttribute(QStringLiteral("w"), x_tailEnd_w);
}
if (!x_tailEnd_len.isEmpty()) {
writer.writeAttribute(QStringLiteral("len"),x_tailEnd_len);}
writer.writeAttribute(QStringLiteral("len"), x_tailEnd_len);
}
}
writer.writeEndElement(); // a:ln
writer.writeEndElement(); // xdr:spPr
// writer style
@ -772,15 +770,21 @@ void DrawingAnchor::saveXmlObjectGraphicFrame(QXmlStreamWriter &writer) const
writer.writeStartElement(QStringLiteral("a:graphic"));
writer.writeStartElement(QStringLiteral("a:graphicData"));
writer.writeAttribute(QStringLiteral("uri"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
writer.writeAttribute(QStringLiteral("uri"),
QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
int idx = m_drawing->workbook->chartFiles().indexOf(m_chartFile);
m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/chart"), QStringLiteral("../charts/chart%1.xml").arg(idx+1));
m_drawing->relationships()->addDocumentRelationship(
QStringLiteral("/chart"), QStringLiteral("../charts/chart%1.xml").arg(idx + 1));
writer.writeEmptyElement(QStringLiteral("c:chart"));
writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count()));
writer.writeAttribute(QStringLiteral("xmlns:c"),
QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
writer.writeAttribute(
QStringLiteral("xmlns:r"),
QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeAttribute(QStringLiteral("r:id"),
QStringLiteral("rId%1").arg(m_drawing->relationships()->count()));
writer.writeEndElement(); // a:graphicData
writer.writeEndElement(); // a:graphic
@ -810,14 +814,18 @@ void DrawingAnchor::saveXmlObjectPicture(QXmlStreamWriter &writer) const
writer.writeEndElement(); // xdr:nvPicPr
m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), QStringLiteral("../media/image%1.%2")
m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"),
QStringLiteral("../media/image%1.%2")
.arg(m_pictureFile->index() + 1)
.arg(m_pictureFile->suffix()));
writer.writeStartElement(QStringLiteral("xdr:blipFill"));
writer.writeEmptyElement(QStringLiteral("a:blip"));
writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeAttribute(QStringLiteral("r:embed"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count()));
writer.writeAttribute(
QStringLiteral("xmlns:r"),
QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeAttribute(QStringLiteral("r:embed"),
QStringLiteral("rId%1").arg(m_drawing->relationships()->count()));
writer.writeStartElement(QStringLiteral("a:stretch"));
writer.writeEmptyElement(QStringLiteral("a:fillRect"));
writer.writeEndElement(); // a:stretch
@ -879,14 +887,23 @@ void DrawingAnchor::saveXmlObjectShape(QXmlStreamWriter &writer) const
writer.writeEndElement(); // a:prstGeom
if (m_pictureFile) {
m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), QStringLiteral("../media/image%1.%2").arg(m_pictureFile->index()+1).arg(m_pictureFile->suffix()));
m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"),
QStringLiteral("../media/image%1.%2")
.arg(m_pictureFile->index() + 1)
.arg(m_pictureFile->suffix()));
writer.writeStartElement(QStringLiteral("a:blipFill"));
writer.writeAttribute(QStringLiteral("dpi"), QString::number(dpiTA));
writer.writeAttribute(QStringLiteral("rotWithShape"), QString::number(rotWithShapeTA));
writer.writeStartElement(QStringLiteral("a:blip"));
writer.writeAttribute(QStringLiteral("r:embed"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); //sp_blip_rembed QStringLiteral("rId%1").arg(m_drawing->relationships()->count()) can't made new pic
writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeAttribute(
QStringLiteral("r:embed"),
QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); // sp_blip_rembed
// QStringLiteral("rId%1").arg(m_drawing->relationships()->count())
// can't made new pic
writer.writeAttribute(
QStringLiteral("xmlns:r"),
QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
if (!sp_blip_cstate.isNull()) {
writer.writeAttribute(QStringLiteral("cstate"), sp_blip_cstate);
}
@ -927,16 +944,18 @@ void DrawingAnchor::saveXmlObjectShape(QXmlStreamWriter &writer) const
if ((!x_tailEnd_tyep.isEmpty()) || (!x_tailEnd_w.isEmpty()) || (!x_tailEnd_len.isEmpty())) {
writer.writeEmptyElement(QStringLiteral("a:tailEnd"));
if (!x_tailEnd_tyep.isEmpty()) {
writer.writeAttribute(QStringLiteral("type"),x_tailEnd_tyep);}
writer.writeAttribute(QStringLiteral("type"), x_tailEnd_tyep);
}
if (!x_tailEnd_w.isEmpty()) {
writer.writeAttribute(QStringLiteral("w"),x_tailEnd_w);}
writer.writeAttribute(QStringLiteral("w"), x_tailEnd_w);
}
if (!x_tailEnd_len.isEmpty()) {
writer.writeAttribute(QStringLiteral("len"),x_tailEnd_len);}
writer.writeAttribute(QStringLiteral("len"), x_tailEnd_len);
}
}
writer.writeEndElement(); // a:ln
writer.writeEndElement(); // xdr:spPr
// writer style
@ -977,7 +996,6 @@ void DrawingAnchor::saveXmlObjectShape(QXmlStreamWriter &writer) const
DrawingAbsoluteAnchor::DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType)
: DrawingAnchor(drawing, objectType)
{
}
// check point
@ -988,22 +1006,15 @@ bool DrawingAbsoluteAnchor::loadFromXml(QXmlStreamReader &reader)
while (!reader.atEnd()) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("pos"))
{
if (reader.name() == QLatin1String("pos")) {
pos = loadXmlPos(reader);
}
else if (reader.name() == QLatin1String("ext"))
{
} else if (reader.name() == QLatin1String("ext")) {
ext = loadXmlExt(reader);
}
else
{
} else {
loadXmlObject(reader);
}
}
else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("absoluteAnchor"))
{
} else if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("absoluteAnchor")) {
break;
}
}
@ -1027,7 +1038,6 @@ void DrawingAbsoluteAnchor::saveToXml(QXmlStreamWriter &writer) const
DrawingOneCellAnchor::DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType)
: DrawingAnchor(drawing, objectType)
{
}
int DrawingOneCellAnchor::row() const
@ -1045,27 +1055,18 @@ bool DrawingOneCellAnchor::loadFromXml(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("oneCellAnchor"));
while (!reader.atEnd())
{
while (!reader.atEnd()) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement)
{
if (reader.name() == QLatin1String("from"))
{
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("from")) {
from = loadXmlMarker(reader, QLatin1String("from"));
}
else if (reader.name() == QLatin1String("ext"))
{
} else if (reader.name() == QLatin1String("ext")) {
ext = loadXmlExt(reader);
}
else
{
} else {
loadXmlObject(reader);
}
}
else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("oneCellAnchor"))
{
} else if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("oneCellAnchor")) {
break;
}
}
@ -1095,7 +1096,6 @@ void DrawingOneCellAnchor::saveToXml(QXmlStreamWriter &writer) const
DrawingTwoCellAnchor::DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType)
: DrawingAnchor(drawing, objectType)
{
}
int DrawingTwoCellAnchor::row() const
@ -1126,30 +1126,22 @@ bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader)
*/
//{{ liufeijin
QXmlStreamAttributes attrs = reader.attributes(); // for absolute twocell aadd by liufeijin 20181024
QXmlStreamAttributes attrs =
reader.attributes(); // for absolute twocell aadd by liufeijin 20181024
editASName = attrs.value(QLatin1String("editAs")).toString();
//}}
while (!reader.atEnd())
{
while (!reader.atEnd()) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement)
{
if (reader.name() == QLatin1String("from"))
{
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("from")) {
from = loadXmlMarker(reader, QLatin1String("from"));
}
else if (reader.name() == QLatin1String("to"))
{
} else if (reader.name() == QLatin1String("to")) {
to = loadXmlMarker(reader, QLatin1String("to"));
}
else if (reader.name() == QLatin1String("clientData"))
{
} else if (reader.name() == QLatin1String("clientData")) {
// clientData
}
else
{
} else {
/*
<xsd:group name="EG_ObjectChoices">
<xsd:sequence>
@ -1167,17 +1159,14 @@ bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader)
loadXmlObject(reader);
}
}
else if (reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("twoCellAnchor"))
{
} else if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("twoCellAnchor")) {
break;
}
}
return true;
}
void DrawingTwoCellAnchor::saveToXml(QXmlStreamWriter &writer) const
{
writer.writeStartElement(QStringLiteral("xdr:twoCellAnchor"));
@ -1196,8 +1185,6 @@ bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader)
writer.writeEmptyElement(QStringLiteral("xdr:clientData"));
writer.writeEndElement(); // xdr:twoCellAnchor
}
QT_END_NAMESPACE_XLSX

View File

@ -1,45 +1,64 @@
// xlsxformat.cpp
#include <QtGlobal>
#include "xlsxformat.h"
#include "xlsxcolor_p.h"
#include "xlsxformat_p.h"
#include "xlsxnumformatparser_p.h"
#include <QDataStream>
#include <QDebug>
#include "xlsxformat.h"
#include "xlsxformat_p.h"
#include "xlsxcolor_p.h"
#include "xlsxnumformatparser_p.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
FormatPrivate::FormatPrivate()
: dirty(true)
, font_dirty(true), font_index_valid(false), font_index(0)
, fill_dirty(true), fill_index_valid(false), fill_index(0)
, border_dirty(true), border_index_valid(false), border_index(0)
, xf_index(-1), xf_indexValid(false)
, is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false)
, font_dirty(true)
, font_index_valid(false)
, font_index(0)
, fill_dirty(true)
, fill_index_valid(false)
, fill_index(0)
, border_dirty(true)
, border_index_valid(false)
, border_index(0)
, xf_index(-1)
, xf_indexValid(false)
, is_dxf_fomat(false)
, dxf_index(-1)
, dxf_indexValid(false)
, theme(0)
{
}
FormatPrivate::FormatPrivate(const FormatPrivate &other)
: QSharedData(other)
, dirty(other.dirty), formatKey(other.formatKey)
, font_dirty(other.font_dirty), font_index_valid(other.font_index_valid), font_key(other.font_key), font_index(other.font_index)
, fill_dirty(other.fill_dirty), fill_index_valid(other.fill_index_valid), fill_key(other.fill_key), fill_index(other.fill_index)
, border_dirty(other.border_dirty), border_index_valid(other.border_index_valid), border_key(other.border_key), border_index(other.border_index)
, xf_index(other.xf_index), xf_indexValid(other.xf_indexValid)
, is_dxf_fomat(other.is_dxf_fomat), dxf_index(other.dxf_index), dxf_indexValid(other.dxf_indexValid)
, dirty(other.dirty)
, formatKey(other.formatKey)
, font_dirty(other.font_dirty)
, font_index_valid(other.font_index_valid)
, font_key(other.font_key)
, font_index(other.font_index)
, fill_dirty(other.fill_dirty)
, fill_index_valid(other.fill_index_valid)
, fill_key(other.fill_key)
, fill_index(other.fill_index)
, border_dirty(other.border_dirty)
, border_index_valid(other.border_index_valid)
, border_key(other.border_key)
, border_index(other.border_index)
, xf_index(other.xf_index)
, xf_indexValid(other.xf_indexValid)
, is_dxf_fomat(other.is_dxf_fomat)
, dxf_index(other.dxf_index)
, dxf_indexValid(other.dxf_indexValid)
, theme(other.theme)
, properties(other.properties)
{
}
FormatPrivate::~FormatPrivate()
{
}
FormatPrivate::~FormatPrivate() {}
/*!
* \class Format
@ -57,7 +76,6 @@ FormatPrivate::~FormatPrivate()
* \value FontScriptSub sub script
*/
/*!
* \enum Format::FontUnderline
*
@ -169,7 +187,6 @@ Format::Format()
Format::Format(const Format &other)
: d(other.d)
{
}
/*!
@ -185,9 +202,7 @@ Format &Format::operator =(const Format &other)
/*!
* Destroys this format.
*/
Format::~Format()
{
}
Format::~Format() {}
/*!
* Returns the number format identifier.
@ -237,14 +252,11 @@ bool Format::isDateTimeFormat() const
{
// NOTICE:
if (hasProperty(FormatPrivate::P_NumFmt_FormatCode))
{
if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) {
// Custom numFmt, so
// Gauss from the number string
return NumFormatParser::isDateTime(numberFormat());
}
else if (hasProperty(FormatPrivate::P_NumFmt_Id))
{
} else if (hasProperty(FormatPrivate::P_NumFmt_Id)) {
// Non-custom numFmt
int idx = numberFormatIndex();
@ -289,8 +301,7 @@ bool Format::hasNumFmtData() const
return false;
if (hasProperty(FormatPrivate::P_NumFmt_Id) ||
hasProperty(FormatPrivate::P_NumFmt_FormatCode) )
{
hasProperty(FormatPrivate::P_NumFmt_FormatCode)) {
return true;
}
return false;
@ -549,7 +560,8 @@ bool Format::hasFontData() const
*/
Format::HorizontalAlignment Format::horizontalAlignment() const
{
return static_cast<Format::HorizontalAlignment>(intProperty(FormatPrivate::P_Alignment_AlignH, AlignHGeneral));
return static_cast<Format::HorizontalAlignment>(
intProperty(FormatPrivate::P_Alignment_AlignH, AlignHGeneral));
}
/*!
@ -557,13 +569,14 @@ Format::HorizontalAlignment Format::horizontalAlignment() const
*/
void Format::setHorizontalAlignment(HorizontalAlignment align)
{
if (hasProperty(FormatPrivate::P_Alignment_Indent)
&&(align != AlignHGeneral && align != AlignLeft && align != AlignRight && align != AlignHDistributed)) {
if (hasProperty(FormatPrivate::P_Alignment_Indent) &&
(align != AlignHGeneral && align != AlignLeft && align != AlignRight &&
align != AlignHDistributed)) {
clearProperty(FormatPrivate::P_Alignment_Indent);
}
if (hasProperty(FormatPrivate::P_Alignment_ShinkToFit)
&& (align == AlignHFill || align == AlignHJustify || align == AlignHDistributed)) {
if (hasProperty(FormatPrivate::P_Alignment_ShinkToFit) &&
(align == AlignHFill || align == AlignHJustify || align == AlignHDistributed)) {
clearProperty(FormatPrivate::P_Alignment_ShinkToFit);
}
@ -575,7 +588,8 @@ void Format::setHorizontalAlignment(HorizontalAlignment align)
*/
Format::VerticalAlignment Format::verticalAlignment() const
{
return static_cast<Format::VerticalAlignment>(intProperty(FormatPrivate::P_Alignment_AlignV, AlignBottom));
return static_cast<Format::VerticalAlignment>(
intProperty(FormatPrivate::P_Alignment_AlignV, AlignBottom));
}
/*!
@ -1115,8 +1129,8 @@ bool Format::hasProtectionData() const
if (!d)
return false;
if (hasProperty(FormatPrivate::P_Protection_Hidden)
|| hasProperty(FormatPrivate::P_Protection_Locked)) {
if (hasProperty(FormatPrivate::P_Protection_Hidden) ||
hasProperty(FormatPrivate::P_Protection_Locked)) {
return true;
}
return false;
@ -1290,13 +1304,15 @@ QVariant Format::property(int propertyId, const QVariant &defaultValue) const
/*!
* \internal
*/
void Format::setProperty(int propertyId, const QVariant &value, const QVariant &clearValue, bool detach)
void Format::setProperty(int propertyId,
const QVariant &value,
const QVariant &clearValue,
bool detach)
{
if (!d)
d = new FormatPrivate;
if (value != clearValue)
{
if (value != clearValue) {
auto it = d->properties.constFind(propertyId);
if (it != d->properties.constEnd() && it.value() == value)
return;
@ -1305,9 +1321,7 @@ void Format::setProperty(int propertyId, const QVariant &value, const QVariant &
d.detach();
d->properties[propertyId] = value;
}
else
{
} else {
if (!d->properties.contains(propertyId))
return;
@ -1321,18 +1335,15 @@ void Format::setProperty(int propertyId, const QVariant &value, const QVariant &
d->xf_indexValid = false;
d->dxf_indexValid = false;
if (propertyId >= FormatPrivate::P_Font_STARTID && propertyId < FormatPrivate::P_Font_ENDID)
{
if (propertyId >= FormatPrivate::P_Font_STARTID && propertyId < FormatPrivate::P_Font_ENDID) {
d->font_dirty = true;
d->font_index_valid = false;
}
else if (propertyId >= FormatPrivate::P_Border_STARTID && propertyId < FormatPrivate::P_Border_ENDID)
{
} else if (propertyId >= FormatPrivate::P_Border_STARTID &&
propertyId < FormatPrivate::P_Border_ENDID) {
d->border_dirty = true;
d->border_index_valid = false;
}
else if (propertyId >= FormatPrivate::P_Fill_STARTID && propertyId < FormatPrivate::P_Fill_ENDID)
{
} else if (propertyId >= FormatPrivate::P_Fill_STARTID &&
propertyId < FormatPrivate::P_Fill_ENDID) {
d->fill_dirty = true;
d->fill_index_valid = false;
}

View File

@ -1,23 +1,27 @@
// xlsxmediafile.cpp
#include <QtGlobal>
#include <QCryptographicHash>
#include "xlsxmediafile_p.h"
#include <QCryptographicHash>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
MediaFile::MediaFile(const QByteArray &bytes, const QString &suffix, const QString &mimeType)
: m_contents(bytes), m_suffix(suffix), m_mimeType(mimeType)
, m_index(0), m_indexValid(false)
: m_contents(bytes)
, m_suffix(suffix)
, m_mimeType(mimeType)
, m_index(0)
, m_indexValid(false)
{
m_hashKey = QCryptographicHash::hash(m_contents, QCryptographicHash::Md5);
}
MediaFile::MediaFile(const QString &fileName)
:m_fileName(fileName), m_index(0), m_indexValid(false)
: m_fileName(fileName)
, m_index(0)
, m_indexValid(false)
{
}
void MediaFile::set(const QByteArray &bytes, const QString &suffix, const QString &mimeType)

View File

@ -2,8 +2,8 @@
#include "xlsxnumformatparser_p.h"
#include <QtGlobal>
#include <QString>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -1,23 +1,23 @@
// xlsxrelationships.cpp
#include <QtGlobal>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QDir>
#include <QFile>
#include <QBuffer>
#include "xlsxrelationships_p.h"
#include <QBuffer>
#include <QDir>
#include <QFile>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
const QLatin1String schema_doc("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
const QLatin1String
schema_doc("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
const QLatin1String schema_msPackage("http://schemas.microsoft.com/office/2006/relationships");
const QLatin1String schema_package("http://schemas.openxmlformats.org/package/2006/relationships");
//const QString schema_worksheet = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
Relationships::Relationships()
{
}
// const QString schema_worksheet =
// QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
Relationships::Relationships() {}
QList<XlsxRelationship> Relationships::documentRelationships(const QString &relativeType) const
{
@ -54,7 +54,9 @@ QList<XlsxRelationship> Relationships::worksheetRelationships(const QString &rel
return relationships(schema_doc + relativeType);
}
void Relationships::addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode)
void Relationships::addWorksheetRelationship(const QString &relativeType,
const QString &target,
const QString &targetMode)
{
addRelationship(schema_doc + relativeType, target, targetMode);
}
@ -69,7 +71,9 @@ QList<XlsxRelationship> Relationships::relationships(const QString &type) const
return res;
}
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;
relation.id = QStringLiteral("rId%1").arg(m_relationships.size() + 1);
@ -86,7 +90,9 @@ void Relationships::saveToXmlFile(QIODevice *device) const
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("Relationships"));
writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships"));
writer.writeAttribute(
QStringLiteral("xmlns"),
QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships"));
for (const XlsxRelationship &relation : m_relationships) {
writer.writeStartElement(QStringLiteral("Relationship"));
writer.writeAttribute(QStringLiteral("Id"), relation.id);

View File

@ -1,34 +1,32 @@
// xlsxrichstring.cpp
#include <QtGlobal>
#include "xlsxrichstring.h"
#include "xlsxformat_p.h"
#include "xlsxrichstring_p.h"
#include <QDebug>
#include <QTextDocument>
#include <QTextFragment>
#include "xlsxrichstring.h"
#include "xlsxrichstring_p.h"
#include "xlsxformat_p.h"
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
RichStringPrivate::RichStringPrivate()
: _dirty(true)
{
}
RichStringPrivate::RichStringPrivate(const RichStringPrivate &other)
:QSharedData(other), fragmentTexts(other.fragmentTexts)
: QSharedData(other)
, fragmentTexts(other.fragmentTexts)
, fragmentFormats(other.fragmentFormats)
, _idKey(other.idKey()), _dirty(other._dirty)
, _idKey(other.idKey())
, _dirty(other._dirty)
{
}
RichStringPrivate::~RichStringPrivate()
{
}
RichStringPrivate::~RichStringPrivate() {}
/*!
\class RichString
@ -59,16 +57,12 @@ RichString::RichString(const QString& text)
RichString::RichString(const RichString &other)
: d(other.d)
{
}
/*!
Destructs the string.
*/
RichString::~RichString()
{
}
RichString::~RichString() {}
/*!
Assigns \a other to this string and returns a reference to this string

View File

@ -1,18 +1,18 @@
// xlsxsharedstrings.cpp
#include <QtGlobal>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QDir>
#include <QFile>
#include <QDebug>
#include <QBuffer>
#include "xlsxcolor_p.h"
#include "xlsxformat_p.h"
#include "xlsxrichstring.h"
#include "xlsxsharedstrings_p.h"
#include "xlsxutility_p.h"
#include "xlsxformat_p.h"
#include "xlsxcolor_p.h"
#include <QBuffer>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -180,12 +180,14 @@ void SharedStrings::writeRichStringPart_rPr(QXmlStreamWriter &writer, const Form
}
if (format.hasProperty(FormatPrivate::P_Font_Family)) {
writer.writeEmptyElement(QStringLiteral("family"));
writer.writeAttribute(QStringLiteral("val"), QString::number(format.intProperty(FormatPrivate::P_Font_Family)));
writer.writeAttribute(QStringLiteral("val"),
QString::number(format.intProperty(FormatPrivate::P_Font_Family)));
}
if (format.hasProperty(FormatPrivate::P_Font_Scheme)) {
writer.writeEmptyElement(QStringLiteral("scheme"));
writer.writeAttribute(QStringLiteral("val"), format.stringProperty(FormatPrivate::P_Font_Scheme));
writer.writeAttribute(QStringLiteral("val"),
format.stringProperty(FormatPrivate::P_Font_Scheme));
}
}
@ -201,7 +203,9 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("sst"));
writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute(
QStringLiteral("xmlns"),
QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute(QStringLiteral("count"), QString::number(m_stringCount));
writer.writeAttribute(QStringLiteral("uniqueCount"), QString::number(m_stringList.size()));
@ -245,7 +249,8 @@ void SharedStrings::readString(QXmlStreamReader &reader)
RichString richString;
while (!reader.atEnd() && !(reader.name() == QLatin1String("si") && reader.tokenType() == QXmlStreamReader::EndElement)) {
while (!reader.atEnd() && !(reader.name() == QLatin1String("si") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("r"))
@ -266,7 +271,8 @@ void SharedStrings::readRichStringPart(QXmlStreamReader &reader, RichString &ric
QString text;
Format format;
while (!reader.atEnd() && !(reader.name() == QLatin1String("r") && reader.tokenType() == QXmlStreamReader::EndElement)) {
while (!reader.atEnd() && !(reader.name() == QLatin1String("r") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("rPr")) {
@ -294,16 +300,19 @@ Format SharedStrings::readRichStringPart_rPr(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("rPr"));
Format format;
while (!reader.atEnd() && !(reader.name() == QLatin1String("rPr") && reader.tokenType() == QXmlStreamReader::EndElement)) {
while (!reader.atEnd() && !(reader.name() == QLatin1String("rPr") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
QXmlStreamAttributes attributes = reader.attributes();
if (reader.name() == QLatin1String("rFont")) {
format.setFontName(attributes.value(QLatin1String("val")).toString());
} else if (reader.name() == QLatin1String("charset")) {
format.setProperty(FormatPrivate::P_Font_Charset, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Charset,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("family")) {
format.setProperty(FormatPrivate::P_Font_Family, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Family,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("b")) {
format.setFontBold(true);
} else if (reader.name() == QLatin1String("i")) {
@ -315,9 +324,11 @@ Format SharedStrings::readRichStringPart_rPr(QXmlStreamReader &reader)
} else if (reader.name() == QLatin1String("shadow")) {
format.setProperty(FormatPrivate::P_Font_Shadow, true);
} else if (reader.name() == QLatin1String("condense")) {
format.setProperty(FormatPrivate::P_Font_Condense, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Condense,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("extend")) {
format.setProperty(FormatPrivate::P_Font_Extend, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Extend,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("color")) {
XlsxColor color;
color.loadFromXml(reader);
@ -341,7 +352,8 @@ Format SharedStrings::readRichStringPart_rPr(QXmlStreamReader &reader)
else if (value == QLatin1String("subscript"))
format.setFontScript(Format::FontScriptSub);
} else if (reader.name() == QLatin1String("scheme")) {
format.setProperty(FormatPrivate::P_Font_Scheme, attributes.value(QLatin1String("val")).toString());
format.setProperty(FormatPrivate::P_Font_Scheme,
attributes.value(QLatin1String("val")).toString());
}
}
}

View File

@ -2,8 +2,8 @@
#include "xlsxsimpleooxmlfile_p.h"
#include <QtGlobal>
#include <QIODevice>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX

View File

@ -1,19 +1,19 @@
// xlsxstyles.cpp
#include <QtGlobal>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QFile>
#include <QMap>
#include <QDataStream>
#include <QDebug>
#include <QBuffer>
#include "xlsxcolor_p.h"
#include "xlsxformat_p.h"
#include "xlsxglobal.h"
#include "xlsxstyles_p.h"
#include "xlsxformat_p.h"
#include "xlsxutility_p.h"
#include "xlsxcolor_p.h"
#include <QBuffer>
#include <QDataStream>
#include <QDebug>
#include <QFile>
#include <QMap>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -23,7 +23,9 @@ QT_BEGIN_NAMESPACE_XLSX
*/
Styles::Styles(CreateFlag flag)
: AbstractOOXmlFile(flag), m_nextCustomNumFmtId(176), m_isIndexedColorsDefault(true)
: AbstractOOXmlFile(flag)
, m_nextCustomNumFmtId(176)
, m_isIndexedColorsDefault(true)
, m_emptyFormatAdded(false)
{
//! Fix me. Should the custom num fmt Id starts with 164 or 176 or others??
@ -67,9 +69,7 @@ Styles::Styles(CreateFlag flag)
}
}
Styles::~Styles()
{
}
Styles::~Styles() {}
Format Styles::xfFormat(int idx) const
{
@ -93,14 +93,12 @@ void Styles::fixNumFmt(const Format &format)
if (!format.hasNumFmtData())
return;
if (format.hasProperty(FormatPrivate::P_NumFmt_Id)
&& !format.stringProperty(FormatPrivate::P_NumFmt_FormatCode).isEmpty())
{
if (format.hasProperty(FormatPrivate::P_NumFmt_Id) &&
!format.stringProperty(FormatPrivate::P_NumFmt_FormatCode).isEmpty()) {
return;
}
if ( m_builtinNumFmtsHash.isEmpty() )
{
if (m_builtinNumFmtsHash.isEmpty()) {
m_builtinNumFmtsHash.insert(QStringLiteral("General"), 0);
m_builtinNumFmtsHash.insert(QStringLiteral("0"), 1);
m_builtinNumFmtsHash.insert(QStringLiteral("0.00"), 2);
@ -109,12 +107,14 @@ void Styles::fixNumFmt(const Format &format)
// m_builtinNumFmtsHash.insert(QStringLiteral("($#,##0_);($#,##0)"), 5);
// m_builtinNumFmtsHash.insert(QStringLiteral("($#,##0_);[Red]($#,##0)"), 6);
// m_builtinNumFmtsHash.insert(QStringLiteral("($#,##0.00_);($#,##0.00)"), 7);
// m_builtinNumFmtsHash.insert(QStringLiteral("($#,##0.00_);[Red]($#,##0.00)"), 8);
// m_builtinNumFmtsHash.insert(QStringLiteral("($#,##0.00_);[Red]($#,##0.00)"),
// 8);
m_builtinNumFmtsHash.insert(QStringLiteral("0%"), 9);
m_builtinNumFmtsHash.insert(QStringLiteral("0.00%"), 10);
m_builtinNumFmtsHash.insert(QStringLiteral("0.00E+00"), 11);
m_builtinNumFmtsHash.insert(QStringLiteral("# ?/?"), 12);
m_builtinNumFmtsHash.insert(QStringLiteral("# ?\?/??"), 13);// Note: "??/" is a c++ trigraph, so escape one "?"
m_builtinNumFmtsHash.insert(QStringLiteral("# ?\?/??"),
13); // Note: "??/" is a c++ trigraph, so escape one "?"
m_builtinNumFmtsHash.insert(QStringLiteral("m/d/yy"), 14);
m_builtinNumFmtsHash.insert(QStringLiteral("d-mmm-yy"), 15);
m_builtinNumFmtsHash.insert(QStringLiteral("d-mmm"), 16);
@ -129,10 +129,12 @@ void Styles::fixNumFmt(const Format &format)
m_builtinNumFmtsHash.insert(QStringLiteral("(#,##0_);[Red](#,##0)"), 38);
m_builtinNumFmtsHash.insert(QStringLiteral("(#,##0.00_);(#,##0.00)"), 39);
m_builtinNumFmtsHash.insert(QStringLiteral("(#,##0.00_);[Red](#,##0.00)"), 40);
// m_builtinNumFmtsHash.insert(QStringLiteral("_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(_)"), 41);
// m_builtinNumFmtsHash.insert(QStringLiteral("_($* #,##0_);_($* (#,##0);_($* \"-\"_);_(_)"), 42);
// m_builtinNumFmtsHash.insert(QStringLiteral("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(_)"), 43);
// m_builtinNumFmtsHash.insert(QStringLiteral("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(_)"), 44);
// m_builtinNumFmtsHash.insert(QStringLiteral("_(* #,##0_);_(* (#,##0);_(*
// \"-\"_);_(_)"), 41); m_builtinNumFmtsHash.insert(QStringLiteral("_($*
// #,##0_);_($* (#,##0);_($* \"-\"_);_(_)"), 42);
// m_builtinNumFmtsHash.insert(QStringLiteral("_(* #,##0.00_);_(* (#,##0.00);_(*
// \"-\"??_);_(_)"), 43); m_builtinNumFmtsHash.insert(QStringLiteral("_($*
// #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(_)"), 44);
m_builtinNumFmtsHash.insert(QStringLiteral("mm:ss"), 45);
m_builtinNumFmtsHash.insert(QStringLiteral("[h]:mm:ss"), 46);
m_builtinNumFmtsHash.insert(QStringLiteral("mm:ss.0"), 47);
@ -141,25 +143,18 @@ void Styles::fixNumFmt(const Format &format)
// dev74
// m_builtinNumFmtsHash.insert(QStringLiteral("0.####"), 176);
}
const auto &str = format.numberFormat();
if (!str.isEmpty())
{
if (!str.isEmpty()) {
QHash<QString, QSharedPointer<XlsxFormatNumberData>>::ConstIterator cIt;
// Assign proper number format index
const auto &it = m_builtinNumFmtsHash.constFind(str);
if (it != m_builtinNumFmtsHash.constEnd())
{
if (it != m_builtinNumFmtsHash.constEnd()) {
const_cast<Format *>(&format)->fixNumberFormat(it.value(), str);
}
else if ((cIt = m_customNumFmtsHash.constFind(str)) != m_customNumFmtsHash.constEnd())
{
} else if ((cIt = m_customNumFmtsHash.constFind(str)) != m_customNumFmtsHash.constEnd()) {
const_cast<Format *>(&format)->fixNumberFormat(cIt.value()->formatIndex, str);
}
else
{
} else {
// Assign a new fmt Id.
const_cast<Format *>(&format)->fixNumberFormat(m_nextCustomNumFmtId, str);
@ -171,31 +166,25 @@ void Styles::fixNumFmt(const Format &format)
m_nextCustomNumFmtId += 1;
}
}
else
{
} else {
const auto id = format.numberFormatIndex();
// Assign proper format code, this is needed by dxf format
const auto &it = m_customNumFmtIdMap.constFind(id);
if (it != m_customNumFmtIdMap.constEnd())
{
if (it != m_customNumFmtIdMap.constEnd()) {
const_cast<Format *>(&format)->fixNumberFormat(id, it.value()->formatString);
}
else
{
} else {
bool found = false;
for ( auto&& it = m_builtinNumFmtsHash.constBegin() ; it != m_builtinNumFmtsHash.constEnd() ; ++it )
{
if (it.value() == id)
{
for (auto &&it = m_builtinNumFmtsHash.constBegin();
it != m_builtinNumFmtsHash.constEnd();
++it) {
if (it.value() == id) {
const_cast<Format *>(&format)->fixNumberFormat(id, it.key());
found = true;
break;
}
}
if (!found)
{
if (!found) {
// Wrong numFmt
const_cast<Format *>(&format)->fixNumberFormat(id, QStringLiteral("General"));
}
@ -212,8 +201,7 @@ void Styles::fixNumFmt(const Format &format)
*/
void Styles::addXfFormat(const Format &format, bool force)
{
if (format.isEmpty())
{
if (format.isEmpty()) {
// Try do something for empty Format.
if (m_emptyFormatAdded && !force)
return;
@ -222,24 +210,20 @@ void Styles::addXfFormat(const Format &format, bool force)
}
// numFmt
if (format.hasNumFmtData() &&
!format.hasProperty(FormatPrivate::P_NumFmt_Id))
{
if (format.hasNumFmtData() && !format.hasProperty(FormatPrivate::P_NumFmt_Id)) {
fixNumFmt(format);
}
// Font
const auto &fontIt = m_fontsHash.constFind(format.fontKey());
if (format.hasFontData() && !format.fontIndexValid())
{
if (format.hasFontData() && !format.fontIndexValid()) {
// Assign proper font index, if has font data.
if (fontIt == m_fontsHash.constEnd())
const_cast<Format *>(&format)->setFontIndex(m_fontsList.size());
else
const_cast<Format *>(&format)->setFontIndex(fontIt->fontIndex());
}
if (fontIt == m_fontsHash.constEnd())
{
if (fontIt == m_fontsHash.constEnd()) {
// Still a valid font if the format has no fontData. (All font properties are default)
m_fontsList.append(format);
m_fontsHash[format.fontKey()] = format;
@ -277,17 +261,14 @@ void Styles::addXfFormat(const Format &format, bool force)
// Format
const auto &formatIt = m_xf_formatsHash.constFind(format.formatKey());
if (!format.isEmpty() && !format.xfIndexValid())
{
if (!format.isEmpty() && !format.xfIndexValid()) {
if (formatIt == m_xf_formatsHash.constEnd())
const_cast<Format *>(&format)->setXfIndex(m_xf_formatsList.size());
else
const_cast<Format *>(&format)->setXfIndex(formatIt->xfIndex());
}
if (formatIt == m_xf_formatsHash.constEnd() ||
force)
{
if (formatIt == m_xf_formatsHash.constEnd() || force) {
m_xf_formatsList.append(format);
m_xf_formatsHash[format.formatKey()] = format;
}
@ -296,28 +277,21 @@ void Styles::addXfFormat(const Format &format, bool force)
void Styles::addDxfFormat(const Format &format, bool force)
{
// numFmt
if ( format.hasNumFmtData() )
{
if (format.hasNumFmtData()) {
fixNumFmt(format);
}
const auto &formatIt = m_dxf_formatsHash.constFind(format.formatKey());
if ( !format.isEmpty() &&
!format.dxfIndexValid() )
{
if (!format.isEmpty() && !format.dxfIndexValid()) {
if (formatIt == m_dxf_formatsHash.constEnd()) // m_xf_formatsHash.constEnd()) // issue #108
{
const_cast<Format *>(&format)->setDxfIndex(m_dxf_formatsList.size());
}
else
{
} else {
const_cast<Format *>(&format)->setDxfIndex(formatIt->dxfIndex());
}
}
if (formatIt == m_xf_formatsHash.constEnd() ||
force )
{
if (formatIt == m_xf_formatsHash.constEnd() || force) {
m_dxf_formatsList.append(format);
m_dxf_formatsHash[format.formatKey()] = format;
}
@ -329,7 +303,9 @@ void Styles::saveToXmlFile(QIODevice *device) const
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("styleSheet"));
writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute(
QStringLiteral("xmlns"),
QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writeNumFmts(writer);
writeFonts(writer);
@ -406,13 +382,13 @@ void Styles::writeFont(QXmlStreamWriter &writer, const Format &format, bool isDx
writer.writeStartElement(QStringLiteral("font"));
// The condense and extend elements are mainly used in dxf format
if (format.hasProperty(FormatPrivate::P_Font_Condense)
&& !format.boolProperty(FormatPrivate::P_Font_Condense)) {
if (format.hasProperty(FormatPrivate::P_Font_Condense) &&
!format.boolProperty(FormatPrivate::P_Font_Condense)) {
writer.writeEmptyElement(QStringLiteral("condense"));
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0"));
}
if (format.hasProperty(FormatPrivate::P_Font_Extend)
&& !format.boolProperty(FormatPrivate::P_Font_Extend)) {
if (format.hasProperty(FormatPrivate::P_Font_Extend) &&
!format.boolProperty(FormatPrivate::P_Font_Extend)) {
writer.writeEmptyElement(QStringLiteral("extend"));
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0"));
}
@ -467,16 +443,21 @@ void Styles::writeFont(QXmlStreamWriter &writer, const Format &format, bool isDx
}
if (format.hasProperty(FormatPrivate::P_Font_Charset)) {
writer.writeEmptyElement(QStringLiteral("charset"));
writer.writeAttribute(QStringLiteral("val"), QString::number(format.intProperty(FormatPrivate::P_Font_Charset)));
writer.writeAttribute(
QStringLiteral("val"),
QString::number(format.intProperty(FormatPrivate::P_Font_Charset)));
}
if (format.hasProperty(FormatPrivate::P_Font_Family)) {
writer.writeEmptyElement(QStringLiteral("family"));
writer.writeAttribute(QStringLiteral("val"), QString::number(format.intProperty(FormatPrivate::P_Font_Family)));
writer.writeAttribute(
QStringLiteral("val"),
QString::number(format.intProperty(FormatPrivate::P_Font_Family)));
}
if (format.hasProperty(FormatPrivate::P_Font_Scheme)) {
writer.writeEmptyElement(QStringLiteral("scheme"));
writer.writeAttribute(QStringLiteral("val"), format.stringProperty(FormatPrivate::P_Font_Scheme));
writer.writeAttribute(QStringLiteral("val"),
format.stringProperty(FormatPrivate::P_Font_Scheme));
}
}
writer.writeEndElement(); // font
@ -515,28 +496,36 @@ void Styles::writeFill(QXmlStreamWriter &writer, const Format &fill, bool isDxf)
{Format::PatternLightTrellis, QStringLiteral("lightTrellis")},
{Format::PatternGray125, QStringLiteral("gray125")},
{Format::PatternGray0625, QStringLiteral("gray0625")},
{Format::PatternLightGrid, QStringLiteral("lightGrid")}
};
{Format::PatternLightGrid, QStringLiteral("lightGrid")}};
writer.writeStartElement(QStringLiteral("fill"));
writer.writeStartElement(QStringLiteral("patternFill"));
Format::FillPattern pattern = fill.fillPattern();
// For normal fill formats, Excel prefer to outputing the default "none" attribute
// But for dxf, Excel prefer to omiting the default "none"
// Though not make any difference, but it make easier to compare origin files with generate files during debug
// Though not make any difference, but it make easier to compare origin files with generate
// files during debug
if (!(pattern == Format::PatternNone && isDxf))
writer.writeAttribute(QStringLiteral("patternType"), patternStrings[pattern]);
// For a solid fill, Excel reverses the role of foreground and background colours
if (fill.fillPattern() == Format::PatternSolid) {
if (fill.hasProperty(FormatPrivate::P_Fill_BgColor))
fill.property(FormatPrivate::P_Fill_BgColor).value<XlsxColor>().saveToXml(writer, QStringLiteral("fgColor"));
fill.property(FormatPrivate::P_Fill_BgColor)
.value<XlsxColor>()
.saveToXml(writer, QStringLiteral("fgColor"));
if (fill.hasProperty(FormatPrivate::P_Fill_FgColor))
fill.property(FormatPrivate::P_Fill_FgColor).value<XlsxColor>().saveToXml(writer, QStringLiteral("bgColor"));
fill.property(FormatPrivate::P_Fill_FgColor)
.value<XlsxColor>()
.saveToXml(writer, QStringLiteral("bgColor"));
} else {
if (fill.hasProperty(FormatPrivate::P_Fill_FgColor))
fill.property(FormatPrivate::P_Fill_FgColor).value<XlsxColor>().saveToXml(writer, QStringLiteral("fgColor"));
fill.property(FormatPrivate::P_Fill_FgColor)
.value<XlsxColor>()
.saveToXml(writer, QStringLiteral("fgColor"));
if (fill.hasProperty(FormatPrivate::P_Fill_BgColor))
fill.property(FormatPrivate::P_Fill_BgColor).value<XlsxColor>().saveToXml(writer, QStringLiteral("bgColor"));
fill.property(FormatPrivate::P_Fill_BgColor)
.value<XlsxColor>()
.saveToXml(writer, QStringLiteral("bgColor"));
}
writer.writeEndElement(); // patternFill
writer.writeEndElement(); // fill
@ -569,14 +558,29 @@ void Styles::writeBorder(QXmlStreamWriter &writer, const Format &border, bool is
}
}
writeSubBorder(writer, QStringLiteral("left"), border.leftBorderStyle(), border.property(FormatPrivate::P_Border_LeftColor).value<XlsxColor>());
writeSubBorder(writer, QStringLiteral("right"), border.rightBorderStyle(), border.property(FormatPrivate::P_Border_RightColor).value<XlsxColor>());
writeSubBorder(writer, QStringLiteral("top"), border.topBorderStyle(), border.property(FormatPrivate::P_Border_TopColor).value<XlsxColor>());
writeSubBorder(writer, QStringLiteral("bottom"), border.bottomBorderStyle(), border.property(FormatPrivate::P_Border_BottomColor).value<XlsxColor>());
writeSubBorder(writer,
QStringLiteral("left"),
border.leftBorderStyle(),
border.property(FormatPrivate::P_Border_LeftColor).value<XlsxColor>());
writeSubBorder(writer,
QStringLiteral("right"),
border.rightBorderStyle(),
border.property(FormatPrivate::P_Border_RightColor).value<XlsxColor>());
writeSubBorder(writer,
QStringLiteral("top"),
border.topBorderStyle(),
border.property(FormatPrivate::P_Border_TopColor).value<XlsxColor>());
writeSubBorder(writer,
QStringLiteral("bottom"),
border.bottomBorderStyle(),
border.property(FormatPrivate::P_Border_BottomColor).value<XlsxColor>());
// Condition DXF formats don't allow diagonal style
if (!isDxf)
writeSubBorder(writer, QStringLiteral("diagonal"), border.diagonalBorderStyle(), border.property(FormatPrivate::P_Border_DiagonalColor).value<XlsxColor>());
writeSubBorder(writer,
QStringLiteral("diagonal"),
border.diagonalBorderStyle(),
border.property(FormatPrivate::P_Border_DiagonalColor).value<XlsxColor>());
if (isDxf) {
// writeSubBorder(wirter, QStringLiteral("vertical"), );
@ -586,7 +590,10 @@ void Styles::writeBorder(QXmlStreamWriter &writer, const Format &border, bool is
writer.writeEndElement(); // border
}
void Styles::writeSubBorder(QXmlStreamWriter &writer, const QString &type, int style, const XlsxColor &color) const
void Styles::writeSubBorder(QXmlStreamWriter &writer,
const QString &type,
int style,
const XlsxColor &color) const
{
if (style == Format::BorderNone) {
writer.writeEmptyElement(type);
@ -607,8 +614,7 @@ void Styles::writeSubBorder(QXmlStreamWriter &writer, const QString &type, int s
{Format::BorderMediumDashDot, QStringLiteral("mediumDashDot")},
{Format::BorderDashDotDot, QStringLiteral("dashDotDot")},
{Format::BorderMediumDashDotDot, QStringLiteral("mediumDashDotDot")},
{Format::BorderSlantDashDot, QStringLiteral("slantDashDot")}
};
{Format::BorderSlantDashDot, QStringLiteral("slantDashDot")}};
writer.writeStartElement(type);
writer.writeAttribute(QStringLiteral("style"), stylesString[style]);
@ -624,7 +630,8 @@ void Styles::writeCellXfs(QXmlStreamWriter &writer) const
for (const Format &format : m_xf_formatsList) {
int xf_id = 0;
writer.writeStartElement(QStringLiteral("xf"));
writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(format.numberFormatIndex()));
writer.writeAttribute(QStringLiteral("numFmtId"),
QString::number(format.numberFormatIndex()));
writer.writeAttribute(QStringLiteral("fontId"), QString::number(format.fontIndex()));
writer.writeAttribute(QStringLiteral("fillId"), QString::number(format.fillIndex()));
writer.writeAttribute(QStringLiteral("borderId"), QString::number(format.borderIndex()));
@ -660,10 +667,12 @@ void Styles::writeCellXfs(QXmlStreamWriter &writer) const
writer.writeAttribute(QStringLiteral("horizontal"), QStringLiteral("justify"));
break;
case Format::AlignHMerge:
writer.writeAttribute(QStringLiteral("horizontal"), QStringLiteral("centerContinuous"));
writer.writeAttribute(QStringLiteral("horizontal"),
QStringLiteral("centerContinuous"));
break;
case Format::AlignHDistributed:
writer.writeAttribute(QStringLiteral("horizontal"), QStringLiteral("distributed"));
writer.writeAttribute(QStringLiteral("horizontal"),
QStringLiteral("distributed"));
break;
default:
break;
@ -682,7 +691,8 @@ void Styles::writeCellXfs(QXmlStreamWriter &writer) const
writer.writeAttribute(QStringLiteral("vertical"), QStringLiteral("justify"));
break;
case Format::AlignVDistributed:
writer.writeAttribute(QStringLiteral("vertical"), QStringLiteral("distributed"));
writer.writeAttribute(QStringLiteral("vertical"),
QStringLiteral("distributed"));
break;
default:
break;
@ -695,7 +705,8 @@ void Styles::writeCellXfs(QXmlStreamWriter &writer) const
if (format.hasProperty(FormatPrivate::P_Alignment_ShinkToFit) && format.shrinkToFit())
writer.writeAttribute(QStringLiteral("shrinkToFit"), QStringLiteral("1"));
if (format.hasProperty(FormatPrivate::P_Alignment_Rotation))
writer.writeAttribute(QStringLiteral("textRotation"), QString::number(format.rotation()));
writer.writeAttribute(QStringLiteral("textRotation"),
QString::number(format.rotation()));
}
writer.writeEndElement(); // xf
@ -721,7 +732,8 @@ void Styles::writeDxf(QXmlStreamWriter &writer, const Format &format) const
if (format.hasNumFmtData()) {
writer.writeEmptyElement(QStringLiteral("numFmt"));
writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(format.numberFormatIndex()));
writer.writeAttribute(QStringLiteral("numFmtId"),
QString::number(format.numberFormatIndex()));
writer.writeAttribute(QStringLiteral("formatCode"), format.numberFormat());
}
@ -760,8 +772,8 @@ bool Styles::readNumFmts(QXmlStreamReader &reader)
const auto count = hasCount ? attributes.value(QLatin1String("count")).toInt() : -1;
// Read utill we find the numFmts end tag or ....
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("numFmts"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("numFmts"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("numFmt")) {
@ -792,8 +804,8 @@ bool Styles::readFonts(QXmlStreamReader &reader)
const auto &attributes = reader.attributes();
const auto hasCount = attributes.hasAttribute(QLatin1String("count"));
const auto count = hasCount ? attributes.value(QLatin1String("count")).toInt() : -1;
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("fonts"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("fonts"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("font")) {
@ -817,17 +829,19 @@ bool Styles::readFonts(QXmlStreamReader &reader)
bool Styles::readFont(QXmlStreamReader &reader, Format &format)
{
Q_ASSERT(reader.name() == QLatin1String("font"));
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("font"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("font"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
const auto &attributes = reader.attributes();
if (reader.name() == QLatin1String("name")) {
format.setFontName(attributes.value(QLatin1String("val")).toString());
} else if (reader.name() == QLatin1String("charset")) {
format.setProperty(FormatPrivate::P_Font_Charset, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Charset,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("family")) {
format.setProperty(FormatPrivate::P_Font_Family, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Family,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("b")) {
format.setFontBold(true);
} else if (reader.name() == QLatin1String("i")) {
@ -839,9 +853,11 @@ bool Styles::readFont(QXmlStreamReader &reader, Format &format)
} else if (reader.name() == QLatin1String("shadow")) {
format.setProperty(FormatPrivate::P_Font_Shadow, true);
} else if (reader.name() == QLatin1String("condense")) {
format.setProperty(FormatPrivate::P_Font_Condense, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Condense,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("extend")) {
format.setProperty(FormatPrivate::P_Font_Extend, attributes.value(QLatin1String("val")).toInt());
format.setProperty(FormatPrivate::P_Font_Extend,
attributes.value(QLatin1String("val")).toInt());
} else if (reader.name() == QLatin1String("color")) {
XlsxColor color;
color.loadFromXml(reader);
@ -866,7 +882,8 @@ bool Styles::readFont(QXmlStreamReader &reader, Format &format)
else if (value == QLatin1String("subscript"))
format.setFontScript(Format::FontScriptSub);
} else if (reader.name() == QLatin1String("scheme")) {
format.setProperty(FormatPrivate::P_Font_Scheme, attributes.value(QLatin1String("val")).toString());
format.setProperty(FormatPrivate::P_Font_Scheme,
attributes.value(QLatin1String("val")).toString());
}
}
}
@ -880,8 +897,8 @@ bool Styles::readFills(QXmlStreamReader &reader)
const auto &attributes = reader.attributes();
const auto hasCount = attributes.hasAttribute(QLatin1String("count"));
const auto count = hasCount ? attributes.value(QLatin1String("count")).toInt() : -1;
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("fills"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("fills"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("fill")) {
@ -925,26 +942,29 @@ bool Styles::readFill(QXmlStreamReader &reader, Format &fill)
{QStringLiteral("lightTrellis"), Format::PatternLightTrellis},
{QStringLiteral("gray125"), Format::PatternGray125},
{QStringLiteral("gray0625"), Format::PatternGray0625},
{QStringLiteral("lightGrid"), Format::PatternLightGrid}
};
{QStringLiteral("lightGrid"), Format::PatternLightGrid}};
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("fill"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("fill"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("patternFill")) {
const auto &attributes = reader.attributes();
if (attributes.hasAttribute(QLatin1String("patternType"))) {
const auto& it = patternValues.constFind(attributes.value(QLatin1String("patternType")).toString());
fill.setFillPattern(it != patternValues.constEnd() ? it.value() : Format::PatternNone);
const auto &it = patternValues.constFind(
attributes.value(QLatin1String("patternType")).toString());
fill.setFillPattern(it != patternValues.constEnd() ? it.value()
: Format::PatternNone);
// parse foreground and background colors if they exist
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("patternFill"))) {
while (!reader.atEnd() &&
!(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("patternFill"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("fgColor")) {
XlsxColor c;
if ( c.loadFromXml(reader) )
{
if (c.loadFromXml(reader)) {
if (fill.fillPattern() == Format::PatternSolid)
fill.setProperty(FormatPrivate::P_Fill_BgColor, c);
else
@ -952,8 +972,7 @@ bool Styles::readFill(QXmlStreamReader &reader, Format &fill)
}
} else if (reader.name() == QLatin1String("bgColor")) {
XlsxColor c;
if ( c.loadFromXml(reader) )
{
if (c.loadFromXml(reader)) {
if (fill.fillPattern() == Format::PatternSolid)
fill.setProperty(FormatPrivate::P_Fill_FgColor, c);
else
@ -977,8 +996,8 @@ bool Styles::readBorders(QXmlStreamReader &reader)
const auto &attributes = reader.attributes();
const auto hasCount = attributes.hasAttribute(QLatin1String("count"));
const auto count = hasCount ? attributes.value(QLatin1String("count")).toInt() : -1;
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("borders"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("borders"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("border")) {
@ -1015,12 +1034,13 @@ bool Styles::readBorder(QXmlStreamReader &reader, Format &border)
else if (isDown)
border.setDiagonalBorderType(Format::DiagonalBorderDown);
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("border"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("border"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("left") || reader.name() == QLatin1String("right")
|| reader.name() == QLatin1String("top") || reader.name() == QLatin1String("bottom")
|| reader.name() == QLatin1String("diagonal") ) {
if (reader.name() == QLatin1String("left") || reader.name() == QLatin1String("right") ||
reader.name() == QLatin1String("top") || reader.name() == QLatin1String("bottom") ||
reader.name() == QLatin1String("diagonal")) {
Format::BorderStyle style(Format::BorderNone);
XlsxColor color;
readSubBorder(reader, reader.name().toString(), style, color);
@ -1049,7 +1069,8 @@ bool Styles::readBorder(QXmlStreamReader &reader, Format &border)
}
}
if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("border"))
if (reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("border"))
break;
}
@ -1062,7 +1083,10 @@ bool Styles::readCellStyleXfs(QXmlStreamReader &reader)
return true;
}
bool Styles::readSubBorder(QXmlStreamReader &reader, const QString &name, Format::BorderStyle &style, XlsxColor &color)
bool Styles::readSubBorder(QXmlStreamReader &reader,
const QString &name,
Format::BorderStyle &style,
XlsxColor &color)
{
Q_ASSERT(reader.name() == name);
@ -1080,8 +1104,7 @@ bool Styles::readSubBorder(QXmlStreamReader &reader, const QString &name, Format
{QStringLiteral("mediumDashDot"), Format::BorderMediumDashDot},
{QStringLiteral("dashDotDot"), Format::BorderDashDotDot},
{QStringLiteral("mediumDashDotDot"), Format::BorderMediumDashDotDot},
{QStringLiteral("slantDashDot"), Format::BorderSlantDashDot}
};
{QStringLiteral("slantDashDot"), Format::BorderSlantDashDot}};
const auto &attributes = reader.attributes();
if (attributes.hasAttribute(QLatin1String("style"))) {
@ -1090,7 +1113,8 @@ bool Styles::readSubBorder(QXmlStreamReader &reader, const QString &name, Format
if (it != stylesStringsMap.constEnd()) {
// get style
style = it.value();
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == name)) {
while (!reader.atEnd() &&
!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == name)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("color"))
@ -1109,8 +1133,8 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
const auto &attributes = reader.attributes();
const auto hasCount = attributes.hasAttribute(QLatin1String("count"));
const auto count = hasCount ? attributes.value(QLatin1String("count")).toInt() : -1;
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("cellXfs"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("cellXfs"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("xf")) {
@ -1124,7 +1148,8 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
if (xfAttrs.hasAttribute(QLatin1String("numFmtId"))) {
const auto numFmtIndex = xfAttrs.value(QLatin1String("numFmtId")).toInt();
const auto apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyNumberFormat")).toString());
const auto apply = parseXsdBoolean(
xfAttrs.value(QLatin1String("applyNumberFormat")).toString());
if (apply) {
const auto &it = m_customNumFmtIdMap.constFind(numFmtIndex);
if (it == m_customNumFmtIdMap.constEnd())
@ -1139,10 +1164,13 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
if (fontIndex >= m_fontsList.size()) {
qDebug("Error read styles.xml, cellXfs fontId");
} else {
const auto apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyFont")).toString());
const auto apply =
parseXsdBoolean(xfAttrs.value(QLatin1String("applyFont")).toString());
if (apply) {
Format fontFormat = m_fontsList[fontIndex];
for (int i=FormatPrivate::P_Font_STARTID; i<FormatPrivate::P_Font_ENDID; ++i) {
for (int i = FormatPrivate::P_Font_STARTID;
i < FormatPrivate::P_Font_ENDID;
++i) {
if (fontFormat.hasProperty(i))
format.setProperty(i, fontFormat.property(i));
}
@ -1160,18 +1188,19 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
// NOTE: MIcrosoft Excel does not have 'applyFill' tag.
//
// bool apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyFill")).toString());
// if (apply)
// bool apply =
// parseXsdBoolean(xfAttrs.value(QLatin1String("applyFill")).toString()); if
// (apply)
{
Format fillFormat = m_fillsList[id];
for (int i=FormatPrivate::P_Fill_STARTID; i<FormatPrivate::P_Fill_ENDID; ++i)
{
for (int i = FormatPrivate::P_Fill_STARTID;
i < FormatPrivate::P_Fill_ENDID;
++i) {
if (fillFormat.hasProperty(i))
format.setProperty(i, fillFormat.property(i));
}
}
}
}
@ -1180,10 +1209,13 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
if (id >= m_bordersList.size()) {
qDebug("Error read styles.xml, cellXfs borderId");
} else {
const auto apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyBorder")).toString());
const auto apply =
parseXsdBoolean(xfAttrs.value(QLatin1String("applyBorder")).toString());
if (apply) {
Format borderFormat = m_bordersList[id];
for (int i=FormatPrivate::P_Border_STARTID; i<FormatPrivate::P_Border_ENDID; ++i) {
for (int i = FormatPrivate::P_Border_STARTID;
i < FormatPrivate::P_Border_ENDID;
++i) {
if (borderFormat.hasProperty(i))
format.setProperty(i, borderFormat.property(i));
}
@ -1191,23 +1223,24 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
}
}
const auto apply = parseXsdBoolean(xfAttrs.value(QLatin1String("applyAlignment")).toString());
const auto apply =
parseXsdBoolean(xfAttrs.value(QLatin1String("applyAlignment")).toString());
if (apply) {
reader.readNextStartElement();
if (reader.name() == QLatin1String("alignment")) {
const auto &alignAttrs = reader.attributes();
if (alignAttrs.hasAttribute(QLatin1String("horizontal"))) {
static const QMap<QString, Format::HorizontalAlignment> alignStringMap = {
{QStringLiteral("left"), Format::AlignLeft},
static const QMap<QString, Format::HorizontalAlignment> alignStringMap =
{{QStringLiteral("left"), Format::AlignLeft},
{QStringLiteral("center"), Format::AlignHCenter},
{QStringLiteral("right"), Format::AlignRight},
{QStringLiteral("justify"), Format::AlignHJustify},
{QStringLiteral("centerContinuous"), Format::AlignHMerge},
{QStringLiteral("distributed"), Format::AlignHDistributed}
};
{QStringLiteral("distributed"), Format::AlignHDistributed}};
const auto& it = alignStringMap.constFind(alignAttrs.value(QLatin1String("horizontal")).toString());
const auto &it = alignStringMap.constFind(
alignAttrs.value(QLatin1String("horizontal")).toString());
if (it != alignStringMap.constEnd())
format.setHorizontalAlignment(it.value());
}
@ -1217,10 +1250,10 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
{QStringLiteral("top"), Format::AlignTop},
{QStringLiteral("center"), Format::AlignVCenter},
{QStringLiteral("justify"), Format::AlignVJustify},
{QStringLiteral("distributed"), Format::AlignVDistributed}
};
{QStringLiteral("distributed"), Format::AlignVDistributed}};
const auto& it = alignStringMap.constFind(alignAttrs.value(QLatin1String("vertical")).toString());
const auto &it = alignStringMap.constFind(
alignAttrs.value(QLatin1String("vertical")).toString());
if (it != alignStringMap.constEnd())
format.setVerticalAlignment(it.value());
}
@ -1231,7 +1264,8 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
}
if (alignAttrs.hasAttribute(QLatin1String("textRotation"))) {
const auto rotation = alignAttrs.value(QLatin1String("textRotation")).toInt();
const auto rotation =
alignAttrs.value(QLatin1String("textRotation")).toInt();
format.setRotation(rotation);
}
@ -1240,7 +1274,6 @@ bool Styles::readCellXfs(QXmlStreamReader &reader)
if (alignAttrs.hasAttribute(QLatin1String("shrinkToFit")))
format.setShrinkToFit(true);
}
}
@ -1264,8 +1297,8 @@ bool Styles::readDxfs(QXmlStreamReader &reader)
const auto &attributes = reader.attributes();
const auto hasCount = attributes.hasAttribute(QLatin1String("count"));
const auto count = hasCount ? attributes.value(QLatin1String("count")).toInt() : -1;
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("dxfs"))) {
while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("dxfs"))) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("dxf"))
@ -1285,7 +1318,8 @@ bool Styles::readDxf(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("dxf"));
Format format;
while (!reader.atEnd() && !(reader.name() == QLatin1String("dxf") && reader.tokenType() == QXmlStreamReader::EndElement)) {
while (!reader.atEnd() && !(reader.name() == QLatin1String("dxf") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("numFmt")) {
@ -1309,13 +1343,13 @@ bool Styles::readDxf(QXmlStreamReader &reader)
bool Styles::readColors(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("colors"));
while (!reader.atEnd() && !(reader.name() == QLatin1String("colors") && reader.tokenType() == QXmlStreamReader::EndElement)) {
while (!reader.atEnd() && !(reader.name() == QLatin1String("colors") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("indexedColors")) {
readIndexedColors(reader);
} else if (reader.name() == QLatin1String("mruColors")) {
}
}
}
@ -1326,7 +1360,8 @@ bool Styles::readIndexedColors(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("indexedColors"));
m_indexedColors.clear();
while (!reader.atEnd() && !(reader.name() == QLatin1String("indexedColors") && reader.tokenType() == QXmlStreamReader::EndElement)) {
while (!reader.atEnd() && !(reader.name() == QLatin1String("indexedColors") &&
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("rgbColor")) {
@ -1382,22 +1417,38 @@ QColor Styles::getColorByIndex(int idx)
{
if (m_indexedColors.isEmpty()) {
m_indexedColors = {
QColor(QRgba64::fromArgb32(0x000000)), QColor(QRgba64::fromArgb32(0xFFFFFF)), QColor(QRgba64::fromArgb32(0xFF0000)), QColor(QRgba64::fromArgb32(0x00FF00)),
QColor(QRgba64::fromArgb32(0x0000FF)), QColor(QRgba64::fromArgb32(0xFFFF00)), QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x000000)), QColor(QRgba64::fromArgb32(0xFFFFFF)), QColor(QRgba64::fromArgb32(0xFF0000)), QColor(QRgba64::fromArgb32(0x00FF00)),
QColor(QRgba64::fromArgb32(0x0000FF)), QColor(QRgba64::fromArgb32(0xFFFF00)), QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x800000)), QColor(QRgba64::fromArgb32(0x008000)), QColor(QRgba64::fromArgb32(0x000080)), QColor(QRgba64::fromArgb32(0x808000)),
QColor(QRgba64::fromArgb32(0x800080)), QColor(QRgba64::fromArgb32(0x008080)), QColor(QRgba64::fromArgb32(0xC0C0C0)), QColor(QRgba64::fromArgb32(0x808080)),
QColor(QRgba64::fromArgb32(0x9999FF)), QColor(QRgba64::fromArgb32(0x993366)), QColor(QRgba64::fromArgb32(0xFFFFCC)), QColor(QRgba64::fromArgb32(0xCCFFFF)),
QColor(QRgba64::fromArgb32(0x660066)), QColor(QRgba64::fromArgb32(0xFF8080)), QColor(QRgba64::fromArgb32(0x0066CC)), QColor(QRgba64::fromArgb32(0xCCCCFF)),
QColor(QRgba64::fromArgb32(0x000080)), QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0xFFFF00)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x800080)), QColor(QRgba64::fromArgb32(0x800000)), QColor(QRgba64::fromArgb32(0x008080)), QColor(QRgba64::fromArgb32(0x0000FF)),
QColor(QRgba64::fromArgb32(0x00CCFF)), QColor(QRgba64::fromArgb32(0xCCFFFF)), QColor(QRgba64::fromArgb32(0xCCFFCC)), QColor(QRgba64::fromArgb32(0xFFFF99)),
QColor(QRgba64::fromArgb32(0x99CCFF)), QColor(QRgba64::fromArgb32(0xFF99CC)), QColor(QRgba64::fromArgb32(0xCC99FF)), QColor(QRgba64::fromArgb32(0xFFCC99)),
QColor(QRgba64::fromArgb32(0x3366FF)), QColor(QRgba64::fromArgb32(0x33CCCC)), QColor(QRgba64::fromArgb32(0x99CC00)), QColor(QRgba64::fromArgb32(0xFFCC00)),
QColor(QRgba64::fromArgb32(0xFF9900)), QColor(QRgba64::fromArgb32(0xFF6600)), QColor(QRgba64::fromArgb32(0x666699)), QColor(QRgba64::fromArgb32(0x969696)),
QColor(QRgba64::fromArgb32(0x003366)), QColor(QRgba64::fromArgb32(0x339966)), QColor(QRgba64::fromArgb32(0x003300)), QColor(QRgba64::fromArgb32(0x333300)),
QColor(QRgba64::fromArgb32(0x993300)), QColor(QRgba64::fromArgb32(0x993366)), QColor(QRgba64::fromArgb32(0x333399)), QColor(QRgba64::fromArgb32(0x333333)),
QColor(QRgba64::fromArgb32(0x000000)), QColor(QRgba64::fromArgb32(0xFFFFFF)),
QColor(QRgba64::fromArgb32(0xFF0000)), QColor(QRgba64::fromArgb32(0x00FF00)),
QColor(QRgba64::fromArgb32(0x0000FF)), QColor(QRgba64::fromArgb32(0xFFFF00)),
QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x000000)), QColor(QRgba64::fromArgb32(0xFFFFFF)),
QColor(QRgba64::fromArgb32(0xFF0000)), QColor(QRgba64::fromArgb32(0x00FF00)),
QColor(QRgba64::fromArgb32(0x0000FF)), QColor(QRgba64::fromArgb32(0xFFFF00)),
QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x800000)), QColor(QRgba64::fromArgb32(0x008000)),
QColor(QRgba64::fromArgb32(0x000080)), QColor(QRgba64::fromArgb32(0x808000)),
QColor(QRgba64::fromArgb32(0x800080)), QColor(QRgba64::fromArgb32(0x008080)),
QColor(QRgba64::fromArgb32(0xC0C0C0)), QColor(QRgba64::fromArgb32(0x808080)),
QColor(QRgba64::fromArgb32(0x9999FF)), QColor(QRgba64::fromArgb32(0x993366)),
QColor(QRgba64::fromArgb32(0xFFFFCC)), QColor(QRgba64::fromArgb32(0xCCFFFF)),
QColor(QRgba64::fromArgb32(0x660066)), QColor(QRgba64::fromArgb32(0xFF8080)),
QColor(QRgba64::fromArgb32(0x0066CC)), QColor(QRgba64::fromArgb32(0xCCCCFF)),
QColor(QRgba64::fromArgb32(0x000080)), QColor(QRgba64::fromArgb32(0xFF00FF)),
QColor(QRgba64::fromArgb32(0xFFFF00)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x800080)), QColor(QRgba64::fromArgb32(0x800000)),
QColor(QRgba64::fromArgb32(0x008080)), QColor(QRgba64::fromArgb32(0x0000FF)),
QColor(QRgba64::fromArgb32(0x00CCFF)), QColor(QRgba64::fromArgb32(0xCCFFFF)),
QColor(QRgba64::fromArgb32(0xCCFFCC)), QColor(QRgba64::fromArgb32(0xFFFF99)),
QColor(QRgba64::fromArgb32(0x99CCFF)), QColor(QRgba64::fromArgb32(0xFF99CC)),
QColor(QRgba64::fromArgb32(0xCC99FF)), QColor(QRgba64::fromArgb32(0xFFCC99)),
QColor(QRgba64::fromArgb32(0x3366FF)), QColor(QRgba64::fromArgb32(0x33CCCC)),
QColor(QRgba64::fromArgb32(0x99CC00)), QColor(QRgba64::fromArgb32(0xFFCC00)),
QColor(QRgba64::fromArgb32(0xFF9900)), QColor(QRgba64::fromArgb32(0xFF6600)),
QColor(QRgba64::fromArgb32(0x666699)), QColor(QRgba64::fromArgb32(0x969696)),
QColor(QRgba64::fromArgb32(0x003366)), QColor(QRgba64::fromArgb32(0x339966)),
QColor(QRgba64::fromArgb32(0x003300)), QColor(QRgba64::fromArgb32(0x333300)),
QColor(QRgba64::fromArgb32(0x993300)), QColor(QRgba64::fromArgb32(0x993366)),
QColor(QRgba64::fromArgb32(0x333399)), QColor(QRgba64::fromArgb32(0x333333)),
};
m_isIndexedColorsDefault = true;
}

View File

@ -8,7 +8,8 @@ QT_BEGIN_NAMESPACE_XLSX
const char *defaultXmlData =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<a:theme xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" name=\"Office \xe4\xb8\xbb\xe9\xa2\x98\">"
"<a:theme xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" name=\"Office "
"\xe4\xb8\xbb\xe9\xa2\x98\">"
"<a:themeElements>"
"<a:clrScheme name=\"Office\">"
"<a:dk1><a:sysClr val=\"windowText\" lastClr=\"000000\"/></a:dk1>"
@ -29,7 +30,8 @@ const char *defaultXmlData =
"<a:latin typeface=\"Cambria\"/>"
"<a:ea typeface=\"\"/>"
"<a:cs typeface=\"\"/>"
"<a:font script=\"Jpan\" typeface=\"\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf\"/>"
"<a:font script=\"Jpan\" typeface=\"\xef\xbc\xad\xef\xbc\xb3 "
"\xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf\"/>"
"<a:font script=\"Hang\" typeface=\"\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95\"/>"
"<a:font script=\"Hans\" typeface=\"\xe5\xae\x8b\xe4\xbd\x93\"/>"
"<a:font script=\"Hant\" typeface=\"\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94\"/>"
@ -63,7 +65,8 @@ const char *defaultXmlData =
"<a:latin typeface=\"Calibri\"/>"
"<a:ea typeface=\"\"/>"
"<a:cs typeface=\"\"/>"
"<a:font script=\"Jpan\" typeface=\"\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf\"/>"
"<a:font script=\"Jpan\" typeface=\"\xef\xbc\xad\xef\xbc\xb3 "
"\xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf\"/>"
"<a:font script=\"Hang\" typeface=\"\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95\"/>"
"<a:font script=\"Hans\" typeface=\"\xe5\xae\x8b\xe4\xbd\x93\"/>"
"<a:font script=\"Hant\" typeface=\"\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94\"/>"
@ -99,24 +102,31 @@ const char *defaultXmlData =
"<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>"
"<a:gradFill rotWithShape=\"1\">"
"<a:gsLst>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:tint val=\"50000\"/><a:satMod val=\"300000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"35000\"><a:schemeClr val=\"phClr\"><a:tint val=\"37000\"/><a:satMod val=\"300000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:tint val=\"15000\"/><a:satMod val=\"350000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:tint val=\"50000\"/><a:satMod "
"val=\"300000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"35000\"><a:schemeClr val=\"phClr\"><a:tint val=\"37000\"/><a:satMod "
"val=\"300000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:tint val=\"15000\"/><a:satMod "
"val=\"350000\"/></a:schemeClr></a:gs>"
"</a:gsLst>"
"<a:lin ang=\"16200000\" scaled=\"1\"/>"
"</a:gradFill>"
"<a:gradFill rotWithShape=\"1\">"
"<a:gsLst>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:shade val=\"51000\"/><a:satMod val=\"130000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"80000\"><a:schemeClr val=\"phClr\"><a:shade val=\"93000\"/><a:satMod val=\"130000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:shade val=\"94000\"/><a:satMod val=\"135000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:shade val=\"51000\"/><a:satMod "
"val=\"130000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"80000\"><a:schemeClr val=\"phClr\"><a:shade val=\"93000\"/><a:satMod "
"val=\"130000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:shade val=\"94000\"/><a:satMod "
"val=\"135000\"/></a:schemeClr></a:gs>"
"</a:gsLst>"
"<a:lin ang=\"16200000\" scaled=\"0\"/>"
"</a:gradFill>"
"</a:fillStyleLst>"
"<a:lnStyleLst>"
"<a:ln w=\"9525\" cap=\"flat\" cmpd=\"sng\" algn=\"ctr\">"
"<a:solidFill><a:schemeClr val=\"phClr\"><a:shade val=\"95000\"/><a:satMod val=\"105000\"/></a:schemeClr></a:solidFill>"
"<a:solidFill><a:schemeClr val=\"phClr\"><a:shade val=\"95000\"/><a:satMod "
"val=\"105000\"/></a:schemeClr></a:solidFill>"
"<a:prstDash val=\"solid\"/>"
"</a:ln>"
"<a:ln w=\"25400\" cap=\"flat\" cmpd=\"sng\" algn=\"ctr\">"
@ -151,7 +161,8 @@ const char *defaultXmlData =
"</a:effectLst>"
"<a:scene3d>"
"<a:camera prst=\"orthographicFront\"><a:rot lat=\"0\" lon=\"0\" rev=\"0\"/></a:camera>"
"<a:lightRig rig=\"threePt\" dir=\"t\"><a:rot lat=\"0\" lon=\"0\" rev=\"1200000\"/></a:lightRig>"
"<a:lightRig rig=\"threePt\" dir=\"t\"><a:rot lat=\"0\" lon=\"0\" "
"rev=\"1200000\"/></a:lightRig>"
"</a:scene3d>"
"<a:sp3d><a:bevelT w=\"63500\" h=\"25400\"/></a:sp3d>"
"</a:effectStyle>"
@ -160,25 +171,31 @@ const char *defaultXmlData =
"<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>"
"<a:gradFill rotWithShape=\"1\">"
"<a:gsLst>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:tint val=\"40000\"/><a:satMod val=\"350000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"40000\"><a:schemeClr val=\"phClr\"><a:tint val=\"45000\"/><a:shade val=\"99000\"/><a:satMod val=\"350000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:shade val=\"20000\"/><a:satMod val=\"255000\"/></a:schemeClr></a:gs></a:gsLst>"
"<a:path path=\"circle\"><a:fillToRect l=\"50000\" t=\"-80000\" r=\"50000\" b=\"180000\"/></a:path>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:tint val=\"40000\"/><a:satMod "
"val=\"350000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"40000\"><a:schemeClr val=\"phClr\"><a:tint val=\"45000\"/><a:shade "
"val=\"99000\"/><a:satMod val=\"350000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:shade val=\"20000\"/><a:satMod "
"val=\"255000\"/></a:schemeClr></a:gs></a:gsLst>"
"<a:path path=\"circle\"><a:fillToRect l=\"50000\" t=\"-80000\" r=\"50000\" "
"b=\"180000\"/></a:path>"
"</a:gradFill>"
"<a:gradFill rotWithShape=\"1\">"
"<a:gsLst>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:tint val=\"80000\"/><a:satMod val=\"300000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:shade val=\"30000\"/><a:satMod val=\"200000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"0\"><a:schemeClr val=\"phClr\"><a:tint val=\"80000\"/><a:satMod "
"val=\"300000\"/></a:schemeClr></a:gs>"
"<a:gs pos=\"100000\"><a:schemeClr val=\"phClr\"><a:shade val=\"30000\"/><a:satMod "
"val=\"200000\"/></a:schemeClr></a:gs>"
"</a:gsLst>"
"<a:path path=\"circle\"><a:fillToRect l=\"50000\" t=\"50000\" r=\"50000\" b=\"50000\"/></a:path>"
"<a:path path=\"circle\"><a:fillToRect l=\"50000\" t=\"50000\" r=\"50000\" "
"b=\"50000\"/></a:path>"
"</a:gradFill>"
"</a:bgFillStyleLst>"
"</a:fmtScheme>"
"</a:themeElements>"
"<a:objectDefaults/>"
"<a:extraClrSchemeLst/>"
"</a:theme>"
;
"</a:theme>";
Theme::Theme(CreateFlag flag)
: AbstractOOXmlFile(flag)

View File

@ -1,20 +1,20 @@
// xlsxutility.cpp
#include "xlsxutility_p.h"
#include "xlsxcellreference.h"
#include <QString>
#include <QPoint>
#include <QRegularExpression>
#include <QMap>
#include <QStringList>
#include <QColor>
#include <QDateTime>
#include <QDebug>
#include "xlsxutility_p.h"
#include <cmath>
#include <string>
#include <QColor>
#include <QDateTime>
#include <QDebug>
#include <QMap>
#include <QPoint>
#include <QRegularExpression>
#include <QString>
#include <QStringList>
QT_BEGIN_NAMESPACE_XLSX
bool parseXsdBoolean(const QString &value, bool defaultValue)
@ -52,7 +52,8 @@ QString getRelFilePath(const QString &filePath)
return ret;
}
ret = QString( filePath.left(idx) + QLatin1String("/_rels/") + filePath.mid(idx+1) + QLatin1String(".rels"));
ret = QString(filePath.left(idx) + QLatin1String("/_rels/") + filePath.mid(idx + 1) +
QLatin1String(".rels"));
return ret;
}
@ -95,23 +96,20 @@ QVariant datetimeFromNumber(double num, bool is1904)
// Remove one hour to see whether the date is Daylight
QDateTime dtNew = dtRet.addMSecs(-3600000); // issue102
if ( dtNew.isDaylightTime() )
{
if (dtNew.isDaylightTime()) {
dtRet = dtNew;
}
double whole = 0;
double fractional = std::modf(num, &whole);
if ( num < double(1) )
{
if (num < double(1)) {
// only time
QTime t = dtRet.time();
return QVariant(t);
}
if ( fractional == 0.0 )
{
if (fractional == 0.0) {
// only date
QDate onlyDT = dtRet.date();
return QVariant(onlyDT);
@ -135,7 +133,8 @@ QString createSafeSheetName(const QString &nameProposal)
return QString();
QString ret = nameProposal;
if (nameProposal.length() > 2 && nameProposal.startsWith(QLatin1Char('\'')) && nameProposal.endsWith(QLatin1Char('\'')))
if (nameProposal.length() > 2 && nameProposal.startsWith(QLatin1Char('\'')) &&
nameProposal.endsWith(QLatin1Char('\'')))
ret = unescapeSheetName(ret);
// Replace invalid chars with space.
@ -157,7 +156,8 @@ QString createSafeSheetName(const QString &nameProposal)
}
/*
* When sheetName contains space or apostrophe, escaped is needed by cellFormula/definedName/chartSerials.
* When sheetName contains space or apostrophe, escaped is needed by
* cellFormula/definedName/chartSerials.
*/
QString escapeSheetName(const QString &sheetName)
{
@ -179,7 +179,8 @@ QString escapeSheetName(const QString &sheetName)
*/
QString unescapeSheetName(const QString &sheetName)
{
Q_ASSERT(sheetName.length() > 2 && sheetName.startsWith(QLatin1Char('\'')) && sheetName.endsWith(QLatin1Char('\'')));
Q_ASSERT(sheetName.length() > 2 && sheetName.startsWith(QLatin1Char('\'')) &&
sheetName.endsWith(QLatin1Char('\'')));
QString name = sheetName.mid(1, sheetName.length() - 2);
name.replace(QLatin1String("\'\'"), QLatin1String("\'"));
@ -206,7 +207,9 @@ bool isSpaceReserveNeeded(const QString &s)
*
* For long run, we need a formula parser.
*/
QString convertSharedFormula(const QString &rootFormula, const CellReference &rootCell, const CellReference &cell)
QString convertSharedFormula(const QString &rootFormula,
const CellReference &rootCell,
const CellReference &cell)
{
Q_UNUSED(rootCell)
Q_UNUSED(cell)
@ -277,7 +280,8 @@ QString convertSharedFormula(const QString &rootFormula, const CellReference &ro
if (p.second != -1 && p.second != 3) {
CellReference oldRef(p.first);
int row = p.second & 0x02 ? oldRef.row() : oldRef.row() - rootCell.row() + cell.row();
int col = p.second & 0x01 ? oldRef.column() : oldRef.column()-rootCell.column()+cell.column();
int col = p.second & 0x01 ? oldRef.column()
: oldRef.column() - rootCell.column() + cell.column();
result.append(CellReference(row, col).toString(p.second & 0x02, p.second & 0x01));
} else {
result.append(p.first);

View File

@ -1,30 +1,31 @@
// xlsxworkbook.cpp
#include <QtGlobal>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QFile>
#include <QBuffer>
#include <QDir>
#include <QtDebug>
#include "xlsxworkbook.h"
#include "xlsxworkbook_p.h"
#include "xlsxsharedstrings_p.h"
#include "xlsxworksheet.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxstyles_p.h"
#include "xlsxformat.h"
#include "xlsxworksheet_p.h"
#include "xlsxformat_p.h"
#include "xlsxmediafile_p.h"
#include "xlsxsharedstrings_p.h"
#include "xlsxstyles_p.h"
#include "xlsxutility_p.h"
#include "xlsxchart.h"
#include "xlsxworkbook_p.h"
#include "xlsxworksheet.h"
#include "xlsxworksheet_p.h"
#include <QBuffer>
#include <QDir>
#include <QFile>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtDebug>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
WorkbookPrivate::WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag) :
AbstractOOXmlFilePrivate(q, flag)
WorkbookPrivate::WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag)
: AbstractOOXmlFilePrivate(q, flag)
{
sharedStrings = QSharedPointer<SharedStrings>(new SharedStrings(flag));
styles = QSharedPointer<Styles>(new Styles(flag));
@ -52,12 +53,9 @@ WorkbookPrivate::WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag) :
Workbook::Workbook(CreateFlag flag)
: AbstractOOXmlFile(new WorkbookPrivate(this, flag))
{
}
Workbook::~Workbook()
{
}
Workbook::~Workbook() {}
bool Workbook::isDate1904() const
{
@ -144,7 +142,10 @@ void Workbook::setDefaultDateFormat(const QString &format)
* \param scope The name of one worksheet, or empty which means golbal scope.
* \return Return false if the name invalid.
*/
bool Workbook::defineName(const QString &name, const QString &formula, const QString &comment, const QString &scope)
bool Workbook::defineName(const QString &name,
const QString &formula,
const QString &comment,
const QString &scope)
{
Q_D(Workbook);
@ -193,18 +194,13 @@ AbstractSheet *Workbook::addSheet(const QString &name, int sheetId, AbstractShee
d->last_sheet_id = sheetId;
AbstractSheet *sheet = NULL;
if (type == AbstractSheet::ST_WorkSheet)
{
if (type == AbstractSheet::ST_WorkSheet) {
// create work sheet (value sheet)
sheet = new Worksheet(name, sheetId, this, F_LoadFromExists);
}
else if (type == AbstractSheet::ST_ChartSheet)
{
} else if (type == AbstractSheet::ST_ChartSheet) {
// create chart sheet
sheet = new Chartsheet(name, sheetId, this, F_LoadFromExists);
}
else
{
} else {
qWarning("unsupported sheet type.");
Q_ASSERT(false);
}
@ -247,16 +243,11 @@ AbstractSheet *Workbook::insertSheet(int index, const QString &name, AbstractShe
++d->last_sheet_id;
AbstractSheet *sheet = NULL;
if ( type == AbstractSheet::ST_WorkSheet )
{
if (type == AbstractSheet::ST_WorkSheet) {
sheet = new Worksheet(sheetName, d->last_sheet_id, this, F_NewFromScratch);
}
else if ( type == AbstractSheet::ST_ChartSheet )
{
} else if (type == AbstractSheet::ST_ChartSheet) {
sheet = new Chartsheet(sheetName, d->last_sheet_id, this, F_NewFromScratch);
}
else
{
} else {
qWarning("unsupported sheet type.");
Q_ASSERT(false);
}
@ -365,7 +356,8 @@ bool Workbook::copySheet(int index, const QString &newName)
int copy_index = 1;
do {
++copy_index;
worksheetName = QStringLiteral("%1(%2)").arg(d->sheets[index]->sheetName()).arg(copy_index);
worksheetName =
QStringLiteral("%1(%2)").arg(d->sheets[index]->sheetName()).arg(copy_index);
} while (d->sheetNames.contains(worksheetName));
}
@ -458,15 +450,20 @@ void Workbook::saveToXmlFile(QIODevice *device) const
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("workbook"));
writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeAttribute(
QStringLiteral("xmlns"),
QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute(
QStringLiteral("xmlns:r"),
QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
writer.writeEmptyElement(QStringLiteral("fileVersion"));
writer.writeAttribute(QStringLiteral("appName"), QStringLiteral("xl"));
writer.writeAttribute(QStringLiteral("lastEdited"), QStringLiteral("4"));
writer.writeAttribute(QStringLiteral("lowestEdited"), QStringLiteral("4"));
writer.writeAttribute(QStringLiteral("rupBuild"), QStringLiteral("4505"));
// writer.writeAttribute(QStringLiteral("codeName"), QStringLiteral("{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}"));
// writer.writeAttribute(QStringLiteral("codeName"),
// QStringLiteral("{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}"));
writer.writeEmptyElement(QStringLiteral("workbookPr"));
if (d->date1904)
@ -502,11 +499,16 @@ void Workbook::saveToXmlFile(QIODevice *device) const
writer.writeAttribute(QStringLiteral("state"), QStringLiteral("veryHidden"));
if (sheet->sheetType() == AbstractSheet::ST_WorkSheet)
d->relationships->addDocumentRelationship(QStringLiteral("/worksheet"), QStringLiteral("worksheets/sheet%1.xml").arg(++worksheetIndex));
d->relationships->addDocumentRelationship(
QStringLiteral("/worksheet"),
QStringLiteral("worksheets/sheet%1.xml").arg(++worksheetIndex));
else
d->relationships->addDocumentRelationship(QStringLiteral("/chartsheet"), QStringLiteral("chartsheets/sheet%1.xml").arg(++chartsheetIndex));
d->relationships->addDocumentRelationship(
QStringLiteral("/chartsheet"),
QStringLiteral("chartsheets/sheet%1.xml").arg(++chartsheetIndex));
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(d->relationships->count()));
writer.writeAttribute(QStringLiteral("r:id"),
QStringLiteral("rId%1").arg(d->relationships->count()));
}
writer.writeEndElement(); // sheets
@ -514,8 +516,11 @@ void Workbook::saveToXmlFile(QIODevice *device) const
writer.writeStartElement(QStringLiteral("externalReferences"));
for (int i = 0; i < d->externalLinks.size(); ++i) {
writer.writeEmptyElement(QStringLiteral("externalReference"));
d->relationships->addDocumentRelationship(QStringLiteral("/externalLink"), QStringLiteral("externalLinks/externalLink%1.xml").arg(i+1));
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(d->relationships->count()));
d->relationships->addDocumentRelationship(
QStringLiteral("/externalLink"),
QStringLiteral("externalLinks/externalLink%1.xml").arg(i + 1));
writer.writeAttribute(QStringLiteral("r:id"),
QStringLiteral("rId%1").arg(d->relationships->count()));
}
writer.writeEndElement(); // externalReferences
}
@ -549,10 +554,13 @@ void Workbook::saveToXmlFile(QIODevice *device) const
writer.writeEndElement(); // workbook
writer.writeEndDocument();
d->relationships->addDocumentRelationship(QStringLiteral("/theme"), QStringLiteral("theme/theme1.xml"));
d->relationships->addDocumentRelationship(QStringLiteral("/styles"), QStringLiteral("styles.xml"));
d->relationships->addDocumentRelationship(QStringLiteral("/theme"),
QStringLiteral("theme/theme1.xml"));
d->relationships->addDocumentRelationship(QStringLiteral("/styles"),
QStringLiteral("styles.xml"));
if (!sharedStrings()->isEmpty())
d->relationships->addDocumentRelationship(QStringLiteral("/sharedStrings"), QStringLiteral("sharedStrings.xml"));
d->relationships->addDocumentRelationship(QStringLiteral("/sharedStrings"),
QStringLiteral("sharedStrings.xml"));
}
bool Workbook::loadFromXmlFile(QIODevice *device)
@ -560,13 +568,10 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
Q_D(Workbook);
QXmlStreamReader reader(device);
while (!reader.atEnd())
{
while (!reader.atEnd()) {
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement)
{
if (reader.name() == QLatin1String("sheet"))
{
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("sheet")) {
QXmlStreamAttributes attributes = reader.attributes();
const auto &name = attributes.value(QLatin1String("name")).toString();
@ -586,24 +591,15 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
XlsxRelationship relationship = d->relationships->getRelationshipById(rId);
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet;
if (relationship.type.endsWith(QLatin1String("/worksheet")))
{
if (relationship.type.endsWith(QLatin1String("/worksheet"))) {
type = AbstractSheet::ST_WorkSheet;
}
else if (relationship.type.endsWith(QLatin1String("/chartsheet")))
{
} else if (relationship.type.endsWith(QLatin1String("/chartsheet"))) {
type = AbstractSheet::ST_ChartSheet;
}
else if (relationship.type.endsWith(QLatin1String("/dialogsheet")))
{
} else if (relationship.type.endsWith(QLatin1String("/dialogsheet"))) {
type = AbstractSheet::ST_DialogSheet;
}
else if (relationship.type.endsWith(QLatin1String("/xlMacrosheet")))
{
} else if (relationship.type.endsWith(QLatin1String("/xlMacrosheet"))) {
type = AbstractSheet::ST_MacroSheet;
}
else
{
} else {
qWarning() << "unknown sheet type : " << relationship.type;
}
@ -611,28 +607,23 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
sheet->setSheetState(state);
QString strFilePath = filePath();
// const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst() + QLatin1String("/") + relationship.target);
// const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst() +
// QLatin1String("/") + relationship.target);
const auto parts = splitPath(strFilePath);
QString fullPath = QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
QString fullPath =
QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
sheet->setFilePath(fullPath);
}
else if (reader.name() == QLatin1String("workbookPr"))
{
} else if (reader.name() == QLatin1String("workbookPr")) {
QXmlStreamAttributes attrs = reader.attributes();
if (attrs.hasAttribute(QLatin1String("date1904")))
d->date1904 = true;
}
else if (reader.name() == QLatin1String("bookviews"))
{
} else if (reader.name() == QLatin1String("bookviews")) {
while (!(reader.name() == QLatin1String("bookviews") &&
reader.tokenType() == QXmlStreamReader::EndElement))
{
reader.tokenType() == QXmlStreamReader::EndElement)) {
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement)
{
if (reader.name() == QLatin1String("workbookView"))
{
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("workbookView")) {
QXmlStreamAttributes attrs = reader.attributes();
if (attrs.hasAttribute(QLatin1String("xWindow")))
d->x_window = attrs.value(QLatin1String("xWindow")).toInt();
@ -641,17 +632,17 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
if (attrs.hasAttribute(QLatin1String("windowWidth")))
d->window_width = attrs.value(QLatin1String("windowWidth")).toInt();
if (attrs.hasAttribute(QLatin1String("windowHeight")))
d->window_height = attrs.value(QLatin1String("windowHeight")).toInt();
d->window_height =
attrs.value(QLatin1String("windowHeight")).toInt();
if (attrs.hasAttribute(QLatin1String("firstSheet")))
d->firstsheet = attrs.value(QLatin1String("firstSheet")).toInt();
if (attrs.hasAttribute(QLatin1String("activeTab")))
d->activesheetIndex = attrs.value(QLatin1String("activeTab")).toInt();
d->activesheetIndex =
attrs.value(QLatin1String("activeTab")).toInt();
}
}
}
}
else if (reader.name() == QLatin1String("externalReference"))
{
} else if (reader.name() == QLatin1String("externalReference")) {
QXmlStreamAttributes attributes = reader.attributes();
const QString rId = attributes.value(QLatin1String("r:id")).toString();
XlsxRelationship relationship = d->relationships->getRelationshipById(rId);
@ -659,7 +650,8 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
QSharedPointer<SimpleOOXmlFile> link(new SimpleOOXmlFile(F_LoadFromExists));
const auto parts = splitPath(filePath());
QString fullPath = QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
QString fullPath =
QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
link->setFilePath(fullPath);
d->externalLinks.append(link);
@ -700,12 +692,9 @@ void Workbook::addMediaFile(std::shared_ptr<MediaFile> media, bool force)
{
Q_D(Workbook);
if (!force)
{
for (int i=0; i<d->mediaFiles.size(); ++i)
{
if (d->mediaFiles[i]->hashKey() == media->hashKey())
{
if (!force) {
for (int i = 0; i < d->mediaFiles.size(); ++i) {
if (d->mediaFiles[i]->hashKey() == media->hashKey()) {
media->setIndex(i);
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -6,22 +6,19 @@
QT_BEGIN_NAMESPACE_XLSX
ZipReader::ZipReader(const QString &filePath) :
m_reader(new QZipReader(filePath))
ZipReader::ZipReader(const QString &filePath)
: m_reader(new QZipReader(filePath))
{
init();
}
ZipReader::ZipReader(QIODevice *device) :
m_reader(new QZipReader(device))
ZipReader::ZipReader(QIODevice *device)
: m_reader(new QZipReader(device))
{
init();
}
ZipReader::~ZipReader()
{
}
ZipReader::~ZipReader() {}
void ZipReader::init()
{

View File

@ -2,10 +2,11 @@
#include "xlsxzipwriter_p.h"
#include <QtGlobal>
#include <QDebug>
#include <private/qzipwriter_p.h>
#include <QDebug>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
ZipWriter::ZipWriter(const QString &filePath)

View File

@ -1,20 +1,20 @@
// main.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVariant>
#include <QDir>
#include <QColor>
#include <QDebug>
#include <iostream>
#include <QColor>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QVariant>
#include <QtCore>
#include <QtGlobal>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
@ -27,8 +27,7 @@ int main(int argc, char *argv[])
QCoreApplication app(argc, argv);
Document xlsxR(":/color.xlsx");
if ( !xlsxR.load() )
{
if (!xlsxR.load()) {
return (-1);
}
@ -53,12 +52,9 @@ void printColor(Cell* cell)
QColor clrForeGround = cell->format().patternForegroundColor();
QColor clrBackGround = cell->format().patternBackgroundColor();
if ( clrForeGround.isValid() &&
clrBackGround.isValid() )
{
if (clrForeGround.isValid() && clrBackGround.isValid()) {
qDebug() << "[debug] color : " << clrForeGround << clrBackGround;
}
}
void saveColor(Cell *cell)
@ -70,6 +66,4 @@ void saveColor(Cell* cell)
// fmt->setTextWarp(false);
cell->format().setPatternBackgroundColor(Qt::blue);
cell->format().setPatternForegroundColor(Qt::white);
}

View File

@ -35,10 +35,10 @@ SOFTWARE.
#ifndef LIBFORT_H
#define LIBFORT_H
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
/*****************************************************************************
* VERSION
@ -49,7 +49,6 @@ SOFTWARE.
#define LIBFORT_REVISION 6
#define LIBFORT_VERSION_STR "0.1.6"
/*****************************************************************************
* Configuration
*****************************************************************************/
@ -63,7 +62,6 @@ SOFTWARE.
# define FT_HAVE_WCHAR
#endif
/*****************************************************************************
* RETURN CODES
*****************************************************************************/
@ -75,9 +73,6 @@ typedef int fort_status_t;
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
#define FT_IS_ERROR(arg) ((arg) < 0)
/**
* @cond HELPER_MACROS
*/
@ -96,7 +91,6 @@ typedef int fort_status_t;
# define FT_UNDEFINED_COMPILER
#endif
/*****************************************************************************
* Declare inline
*****************************************************************************/
@ -107,7 +101,6 @@ typedef int fort_status_t;
# define FT_INLINE __inline
#endif /* if defined(__cplusplus) */
/*****************************************************************************
* C++ needs to know that types and declarations are C, not C++.
*****************************************************************************/
@ -120,15 +113,12 @@ typedef int fort_status_t;
# define FT_END_DECLS
#endif
/*****************************************************************************
* Helper macros
*****************************************************************************/
#define FT_STR_2_CAT_(arg1, arg2) \
arg1##arg2
#define FT_STR_2_CAT(arg1, arg2) \
FT_STR_2_CAT_(arg1, arg2)
#define FT_STR_2_CAT_(arg1, arg2) arg1##arg2
#define FT_STR_2_CAT(arg1, arg2) FT_STR_2_CAT_(arg1, arg2)
/**
* @interanl
@ -153,56 +143,87 @@ static FT_INLINE int ft_check_if_wstring_helper(const wchar_t *str)
#define FT_PP_NARG_(...) \
FT_EXPAND_(FT_NARGS_IMPL_(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define FT_CHECK_IF_STR_32(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_31(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_31(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_30(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_30(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_29(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_29(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_28(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_28(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_27(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_27(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_26(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_26(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_25(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_25(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_24(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_24(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_23(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_23(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_22(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_22(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_21(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_21(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_20(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_20(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_19(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_19(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_18(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_18(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_17(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_17(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_16(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_16(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_15(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_15(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_14(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_14(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_13(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_13(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_12(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_12(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_11(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_11(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_10(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_10(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_9(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_9(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_8(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_8(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_7(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_7(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_6(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_6(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_5(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_5(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_4(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_4(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_3(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_3(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_2(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_2(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_1(checker,__VA_ARGS__)))
#define FT_CHECK_IF_STR_32(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_31(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_31(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_30(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_30(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_29(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_29(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_28(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_28(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_27(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_27(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_26(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_26(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_25(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_25(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_24(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_24(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_23(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_23(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_22(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_22(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_21(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_21(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_20(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_20(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_19(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_19(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_18(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_18(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_17(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_17(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_16(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_16(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_15(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_15(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_14(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_14(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_13(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_13(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_12(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_12(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_11(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_11(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_10(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_10(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_9(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_9(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_8(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_8(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_7(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_7(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_6(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_6(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_5(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_5(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_4(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_4(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_3(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_3(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_2(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_2(checker, arg, ...) \
(checker(arg), FT_EXPAND_(FT_CHECK_IF_STR_1(checker, __VA_ARGS__)))
#define FT_CHECK_IF_STR_1(checker, arg) (checker(arg))
#define FT_CHECK_IF_ARGS_ARE_STRINGS__(checker,func, ...) \
FT_EXPAND_(func(checker,__VA_ARGS__))
#define FT_CHECK_IF_ARGS_ARE_STRINGS__(checker, func, ...) FT_EXPAND_(func(checker, __VA_ARGS__))
#define FT_CHECK_IF_ARGS_ARE_STRINGS_(checker, basis, n, ...) \
FT_CHECK_IF_ARGS_ARE_STRINGS__(checker, FT_STR_2_CAT_(basis, n), __VA_ARGS__)
#define FT_CHECK_IF_ARGS_ARE_STRINGS(...) \
FT_CHECK_IF_ARGS_ARE_STRINGS_(ft_check_if_string_helper,FT_CHECK_IF_STR_,FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)
FT_CHECK_IF_ARGS_ARE_STRINGS_( \
ft_check_if_string_helper, FT_CHECK_IF_STR_, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)
#ifdef FT_HAVE_WCHAR
# define CHECK_IF_ARGS_ARE_WSTRINGS(...) \
FT_CHECK_IF_ARGS_ARE_STRINGS_(ft_check_if_wstring_helper,FT_CHECK_IF_STR_,FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)
FT_CHECK_IF_ARGS_ARE_STRINGS_( \
ft_check_if_wstring_helper, FT_CHECK_IF_STR_, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)
#endif
/**
* @endcond
*/
/*****************************************************************************
* Attribute format for argument checking
*****************************************************************************/
@ -214,7 +235,6 @@ static FT_INLINE int ft_check_if_wstring_helper(const wchar_t *str)
# define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check)
#endif /* defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER) */
/*****************************************************************************
* libfort API
*****************************************************************************/
@ -308,8 +328,6 @@ size_t ft_cur_col(ft_table_t *table);
*/
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col);
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
/**
@ -394,7 +412,6 @@ int ft_printf_ln_impl(ft_table_t *table, const char *fmt, ...) FT_PRINTF_ATTRIBU
*/
void ft_set_default_printf_field_separator(char separator);
/**
* Write strings to the table.
*
@ -410,7 +427,8 @@ void ft_set_default_printf_field_separator(char separator);
* - (<0): In case of error
*/
#define ft_write(table, ...) \
(0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
(0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) \
: ft_nwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
/**
* Write strings to the table and go to the next line.
@ -428,7 +446,8 @@ void ft_set_default_printf_field_separator(char separator);
* - (<0): In case of error
*/
#define ft_write_ln(table, ...) \
(0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
(0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) \
: ft_nwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
/**
* Write specified number of strings to the table.
@ -481,10 +500,6 @@ int ft_nwrite(ft_table_t *table, size_t count, const char *cell_content, ...);
*/
int ft_nwrite_ln(ft_table_t *table, size_t count, const char *cell_content, ...);
/**
* Write strings from the array to the table.
*
@ -522,7 +537,6 @@ int ft_row_write(ft_table_t *table, size_t cols, const char *row_cells[]);
*/
int ft_row_write_ln(ft_table_t *table, size_t cols, const char *row_cells[]);
/**
* Write strings from the 2D array to the table.
*
@ -562,7 +576,6 @@ int ft_table_write(ft_table_t *table, size_t rows, size_t cols, const char *tabl
*/
int ft_table_write_ln(ft_table_t *table, size_t rows, size_t cols, const char *table_cells[]);
/**
* Add separator after the current row.
*
@ -574,7 +587,6 @@ int ft_table_write_ln(ft_table_t *table, size_t rows, size_t cols, const char *t
*/
int ft_add_separator(ft_table_t *table);
/**
* Convert table to string representation.
*
@ -594,12 +606,6 @@ int ft_add_separator(ft_table_t *table);
*/
const char *ft_to_string(const ft_table_t *table);
/**
* Structure describing border appearance.
*/
@ -648,8 +654,6 @@ extern const struct ft_border_style *const FT_BOLD2_STYLE;
extern const struct ft_border_style *const FT_FRAME_STYLE;
/** @} */
/**
* Set default border style for all new formatted tables.
*
@ -674,8 +678,6 @@ int ft_set_default_border_style(const struct ft_border_style *style);
*/
int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style);
/**
* @name Special macros to define cell position (row and column).
* @{
@ -686,8 +688,6 @@ int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style);
#define FT_CUR_ROW (UINT_MAX - 1) /**< Current row */
/** @} */
/**
* @name Cell properties identifiers.
* @{
@ -707,7 +707,6 @@ int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style);
#define FT_CPROP_CONT_TEXT_STYLE (0x01U << 12) /**< Cell content text style */
/** @} */
/**
* Colors.
*/
@ -745,7 +744,6 @@ enum ft_text_style {
FT_TSTYLE_HIDDEN = (1U << 7) /**< Hidden (useful for passwords) */
};
/**
* Alignment of cell content.
*/
@ -795,7 +793,6 @@ int ft_set_default_cell_prop(uint32_t property, int value);
*/
int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t property, int value);
/**
* @name Table properties identifiers.
* @{
@ -806,8 +803,6 @@ int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t propert
#define FT_TPROP_BOTTOM_MARGIN (0x01U << 3)
/** @} */
/**
* Set default table property.
*
@ -836,7 +831,6 @@ int ft_set_default_tbl_prop(uint32_t property, int value);
*/
int ft_set_tbl_prop(ft_table_t *table, uint32_t property, int value);
/**
* Set column span for the specified cell of the table.
*
@ -854,7 +848,6 @@ int ft_set_tbl_prop(ft_table_t *table, uint32_t property, int value);
*/
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span);
/**
* Set functions for memory allocation and deallocation to be used instead of
* standard ones.
@ -871,20 +864,17 @@ int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
*/
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr));
#ifdef FT_HAVE_WCHAR
int ft_wprintf(ft_table_t *table, const wchar_t *fmt, ...);
int ft_wprintf_ln(ft_table_t *table, const wchar_t *fmt, ...);
# define ft_wwrite(table, ...) \
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) \
: ft_nwwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
# define ft_wwrite_ln(table, ...) \
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) \
: ft_nwwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
int ft_nwwrite(ft_table_t *table, size_t n, const wchar_t *cell_content, ...);
int ft_nwwrite_ln(ft_table_t *table, size_t n, const wchar_t *cell_content, ...);
@ -897,8 +887,6 @@ int ft_table_wwrite_ln(ft_table_t *table, size_t rows, size_t cols, const wchar_
const wchar_t *ft_to_wstring(const ft_table_t *table);
#endif
FT_END_DECLS
#endif /* LIBFORT_H */

View File

@ -3,21 +3,19 @@
#include <iostream>
#include <vector>
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVariant>
#include <QDir>
#include <QDebug>
#include <iostream>
#include <QDir>
#include <QVariant>
#include <QtCore>
#include <QtGlobal>
using namespace std;
// [0] include QXlsx headers
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
@ -28,8 +26,7 @@ int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
if ( argc != 2 )
{
if (argc != 2) {
std::cout << "[Usage] ShowConsole *.xlsx" << std::endl;
return 0;
}
@ -40,8 +37,7 @@ int main(int argc, char *argv[])
// tried to load xlsx using temporary document
QXlsx::Document xlsxTmp(xlsxFileName);
if ( !xlsxTmp.isLoadPackage() )
{
if (!xlsxTmp.isLoadPackage()) {
qCritical() << "Failed to load" << xlsxFileName;
return (-1); // failed to load
}
@ -51,8 +47,7 @@ int main(int argc, char *argv[])
xlsxDoc.isLoadPackage();
int sheetIndexNumber = 0;
foreach( QString curretnSheetName, xlsxDoc.sheetNames() )
{
foreach (QString curretnSheetName, xlsxDoc.sheetNames()) {
QXlsx::AbstractSheet *currentSheet = xlsxDoc.sheet(curretnSheetName);
if (NULL == currentSheet)
continue;
@ -68,25 +63,20 @@ int main(int argc, char *argv[])
QString strSheetName = wsheet->sheetName(); // sheet name
// display sheet name
std::cout
<< std::string( strSheetName.toLocal8Bit() )
<< std::endl;
std::cout << std::string(strSheetName.toLocal8Bit()) << std::endl;
QVector<CellLocation> clList = wsheet->getFullCells(&maxRow, &maxCol);
QVector<QVector<QString>> cellValues;
for (int rc = 0; rc < maxRow; rc++)
{
for (int rc = 0; rc < maxRow; rc++) {
QVector<QString> tempValue;
for (int cc = 0; cc < maxCol; cc++)
{
for (int cc = 0; cc < maxCol; cc++) {
tempValue.push_back(QString(""));
}
cellValues.push_back(tempValue);
}
for ( int ic = 0; ic < clList.size(); ++ic )
{
for (int ic = 0; ic < clList.size(); ++ic) {
// cell location
CellLocation cl = clList.at(ic);
@ -109,10 +99,8 @@ int main(int argc, char *argv[])
}
fort::table fortTable;
for (int rc = 0; rc < maxRow; rc++)
{
for (int cc = 0; cc < maxCol; cc++)
{
for (int rc = 0; rc < maxRow; rc++) {
for (int cc = 0; cc < maxCol; cc++) {
QString strTemp = cellValues[rc][cc];
fortTable << std::string(strTemp.toLocal8Bit()); // display value
}
@ -124,6 +112,5 @@ int main(int argc, char *argv[])
sheetIndexNumber++;
}
return 0;
}

View File

@ -1,21 +1,20 @@
// calendar.cpp
#include <QtGlobal>
#include <QtCore>
#include "xlsxcellrange.h"
#include "xlsxdocument.h"
#include "xlsxformat.h"
#include "xlsxcellrange.h"
#include "xlsxworksheet.h"
#include <QtCore>
#include <QtGlobal>
QXLSX_USE_NAMESPACE
int calendar()
{
Document xlsx;
QDate today(QDate::currentDate());
for (int month=1; month<=12; ++month)
{
for (int month = 1; month <= 12; ++month) {
xlsx.addSheet(QLocale().monthName(month));
xlsx.currentWorksheet()->setGridLinesVisible(false);
@ -155,7 +154,6 @@ int calendar()
if (dow == 7)
rownum++;
}
}
xlsx.saveAs("calendar1.xlsx");

View File

@ -1,12 +1,12 @@
// chart.cpp
#include <QtGlobal>
#include <QtCore>
#include <QDebug>
#include "xlsxdocument.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxdocument.h"
#include <QDebug>
#include <QtCore>
#include <QtGlobal>
QXLSX_USE_NAMESPACE
@ -14,8 +14,7 @@ int chart()
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i)
{
for (int i = 1; i < 10; ++i) {
xlsx.write(i, 1, i * i * i); // A1:A9
xlsx.write(i, 2, i * i); // B1:B9
xlsx.write(i, 3, i * i - 1); // C1:C9
@ -82,8 +81,7 @@ int chart()
//![2]
Document xlsx2("chart1.xlsx");
if ( xlsx2.load() )
{
if (xlsx2.load()) {
xlsx2.saveAs("chart2.xlsx");
}

View File

@ -1,12 +1,12 @@
// chartextended.cpp
#include <QtGlobal>
#include <QtCore>
#include <QDebug>
#include "xlsxdocument.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxdocument.h"
#include <QDebug>
#include <QtCore>
#include <QtGlobal>
QXLSX_USE_NAMESPACE
@ -18,21 +18,18 @@ QXLSX_USE_NAMESPACE
int chartExtended()
{
Document xlsx;
for (int i=1; i<10; ++i)
{
for (int i = 1; i < 10; ++i) {
xlsx.write(1, i + 1, "Pos " + QString::number(i));
}
xlsx.write(2, 1, "Set 1");
xlsx.write(3, 1, "Set 2");
for (int i=1; i<10; ++i)
{
for (int i = 1; i < 10; ++i) {
xlsx.write(2, i + 1, i * i * i); // A2:A10
xlsx.write(3, i + 1, i * i); // B2:B10
}
Chart *barChart1 = xlsx.insertChart(4, 3, QSize(300, 300));
barChart1->setChartType(Chart::CT_BarChart);
barChart1->setChartLegend(Chart::Right);
@ -69,14 +66,12 @@ int chartExtended()
// Messreihen
barChart5->addSeries(CellRange(1, 1, 3, 10));
//![2]
xlsx.saveAs("chartExtended1.xlsx");
//![2]
Document xlsx2("chartExtended1.xlsx");
if ( xlsx2.load() )
{
if (xlsx2.load()) {
xlsx2.saveAs("chartExtended2.xlsx");
}

View File

@ -1,11 +1,11 @@
// chartsheet.cpp
#include <QtGlobal>
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
#include <QtGlobal>
QXLSX_USE_NAMESPACE
@ -13,8 +13,7 @@ int chartsheet()
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i)
{
for (int i = 1; i < 10; ++i) {
xlsx.write(i, 1, i * i);
}
//![0]
@ -32,8 +31,7 @@ int chartsheet()
//![2]
Document xlsx2("chartsheet1.xlsx");
if ( xlsx2.load() )
{
if (xlsx2.load()) {
xlsx2.saveAs("chartsheet2.xlsx");
}

View File

@ -1,9 +1,9 @@
// datavalidation.cpp
#include <QtGlobal>
#include "xlsxdocument.h"
#include "xlsxdatavalidation.h"
#include "xlsxdocument.h"
#include <QtGlobal>
QXLSX_USE_NAMESPACE

View File

@ -1,11 +1,11 @@
// definename.cpp
#include <QtGlobal>
#include <QtCore>
#include <QDebug>
#include "xlsxdocument.h"
#include <QDebug>
#include <QtCore>
#include <QtGlobal>
QXLSX_USE_NAMESPACE
int definename()
@ -38,8 +38,7 @@ int definename()
xlsx.saveAs("definename1.xlsx");
Document xlsx2("definename1.xlsx");
if ( xlsx2.load() )
{
if (xlsx2.load()) {
xlsx2.saveAs("definename2.xlsx");
}

Some files were not shown because too many files have changed in this diff Show More