1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-16 04:42:53 +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;
@ -22,12 +22,11 @@ extern int test(QVector<QVariant> params);
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication app(argc, argv);
QVector<QVariant> testParams;
int ret = test(testParams);
QVector<QVariant> testParams;
int ret = test(testParams);
// qDebug() << "test return value : " << ret;
return 0;
return 0;
}

View File

@ -1,34 +1,34 @@
// test.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <QDir>
#include <iostream>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#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"
int test( QVector<QVariant> params );
int test1( QVector<QVariant> params );
int test2( QVector<QVariant> params );
int test(QVector<QVariant> params);
int test1(QVector<QVariant> params);
int test2(QVector<QVariant> params);
int test( QVector<QVariant> params )
int test(QVector<QVariant> params)
{
// return test1( params );
return test2( params );
return test2(params);
}
int test1( QVector<QVariant> params )
int test1(QVector<QVariant> params)
{
qDebug() << "[debug] current path : " << QDir::currentPath();
@ -36,33 +36,33 @@ int test1( QVector<QVariant> params )
Document doc;
doc.write( "A1", QVariant(QDateTime::currentDateTimeUtc()) );
doc.write( "A2", QVariant(double(10.5)) );
doc.write( "A3", QVariant(QDate(2019, 10, 9)) );
doc.write( "A4", QVariant(QTime(10, 9, 5)) );
doc.write( "A5", QVariant((int) 40000) );
doc.write("A1", QVariant(QDateTime::currentDateTimeUtc()));
doc.write("A2", QVariant(double(10.5)));
doc.write("A3", QVariant(QDate(2019, 10, 9)));
doc.write("A4", QVariant(QTime(10, 9, 5)));
doc.write("A5", QVariant((int) 40000));
qDebug() << "doc.read()";
qDebug() << doc.read( 1, 1 ).type() << doc.read( 1, 1 );
qDebug() << doc.read( 2, 1 ).type() << doc.read( 2, 1 );
qDebug() << doc.read( 3, 1 ).type() << doc.read( 3, 1 );
qDebug() << doc.read( 4, 1 ).type() << doc.read( 4, 1 );
qDebug() << doc.read( 5, 1 ).type() << doc.read( 5, 1 );
qDebug() << doc.read(1, 1).type() << doc.read(1, 1);
qDebug() << doc.read(2, 1).type() << doc.read(2, 1);
qDebug() << doc.read(3, 1).type() << doc.read(3, 1);
qDebug() << doc.read(4, 1).type() << doc.read(4, 1);
qDebug() << doc.read(5, 1).type() << doc.read(5, 1);
qDebug() << "\n";
qDebug() << "doc.cellAt()->value()";
qDebug() << doc.cellAt( 1, 1 )->value().type() << doc.cellAt( 1, 1 )->value();
qDebug() << doc.cellAt( 2, 1 )->value().type() << doc.cellAt( 2, 1 )->value();
qDebug() << doc.cellAt( 3, 1 )->value().type() << doc.cellAt( 3, 1 )->value();
qDebug() << doc.cellAt( 4, 1 )->value().type() << doc.cellAt( 4, 1 )->value();
qDebug() << doc.cellAt( 5, 1 )->value().type() << doc.cellAt( 5, 1 )->value();
qDebug() << doc.cellAt(1, 1)->value().type() << doc.cellAt(1, 1)->value();
qDebug() << doc.cellAt(2, 1)->value().type() << doc.cellAt(2, 1)->value();
qDebug() << doc.cellAt(3, 1)->value().type() << doc.cellAt(3, 1)->value();
qDebug() << doc.cellAt(4, 1)->value().type() << doc.cellAt(4, 1)->value();
qDebug() << doc.cellAt(5, 1)->value().type() << doc.cellAt(5, 1)->value();
doc.saveAs("datetime.xlsx");
return 0;
}
int test2( QVector<QVariant> params )
int test2(QVector<QVariant> params)
{
qDebug() << "[debug] current path : " << QDir::currentPath();
@ -72,26 +72,26 @@ int test2( QVector<QVariant> params )
Document doc;
doc.write( "A1", QVariant(QDateTime::currentDateTimeUtc()) );
doc.write( "A2", QVariant(double(10.5)) );
doc.write( "A3", QVariant(QDate(2019, 10, 9)) );
doc.write( "A4", QVariant(QTime(10, 9, 5)) );
doc.write( "A5", QVariant((int) 40000) );
doc.write("A1", QVariant(QDateTime::currentDateTimeUtc()));
doc.write("A2", QVariant(double(10.5)));
doc.write("A3", QVariant(QDate(2019, 10, 9)));
doc.write("A4", QVariant(QTime(10, 9, 5)));
doc.write("A5", QVariant((int) 40000));
qDebug() << "doc.read()";
qDebug() << doc.read( 1, 1 ).type() << doc.read( 1, 1 );
qDebug() << doc.read( 2, 1 ).type() << doc.read( 2, 1 );
qDebug() << doc.read( 3, 1 ).type() << doc.read( 3, 1 );
qDebug() << doc.read( 4, 1 ).type() << doc.read( 4, 1 );
qDebug() << doc.read( 5, 1 ).type() << doc.read( 5, 1 );
qDebug() << doc.read(1, 1).type() << doc.read(1, 1);
qDebug() << doc.read(2, 1).type() << doc.read(2, 1);
qDebug() << doc.read(3, 1).type() << doc.read(3, 1);
qDebug() << doc.read(4, 1).type() << doc.read(4, 1);
qDebug() << doc.read(5, 1).type() << doc.read(5, 1);
qDebug() << "\n";
qDebug() << "doc.cellAt()->value()";
qDebug() << doc.cellAt( 1, 1 )->value().type() << doc.cellAt( 1, 1 )->value();
qDebug() << doc.cellAt( 2, 1 )->value().type() << doc.cellAt( 2, 1 )->value();
qDebug() << doc.cellAt( 3, 1 )->value().type() << doc.cellAt( 3, 1 )->value();
qDebug() << doc.cellAt( 4, 1 )->value().type() << doc.cellAt( 4, 1 )->value();
qDebug() << doc.cellAt( 5, 1 )->value().type() << doc.cellAt( 5, 1 )->value();
qDebug() << doc.cellAt(1, 1)->value().type() << doc.cellAt(1, 1)->value();
qDebug() << doc.cellAt(2, 1)->value().type() << doc.cellAt(2, 1)->value();
qDebug() << doc.cellAt(3, 1)->value().type() << doc.cellAt(3, 1)->value();
qDebug() << doc.cellAt(4, 1)->value().type() << doc.cellAt(4, 1)->value();
qDebug() << doc.cellAt(5, 1)->value().type() << doc.cellAt(5, 1)->value();
qDebug() << "\n";
doc.saveAs("datetime.xlsx");
@ -99,81 +99,78 @@ int test2( QVector<QVariant> params )
qDebug() << "\n\ndoc2\n";
Document doc2("datetime.xlsx");
if ( !doc2.load() )
{
qWarning() << "failed to load datetime.xlsx" ;
if (!doc2.load()) {
qWarning() << "failed to load datetime.xlsx";
return (-1);
}
qDebug() << "\n\n";
doc2.write( "A6", QVariant(QDateTime::currentDateTimeUtc()) );
doc2.write( "A7", QVariant(double(10.5)) );
doc2.write( "A8", QVariant(QDate(2019, 10, 9)) );
doc2.write( "A9", QVariant(QTime(10, 9, 5)) );
doc2.write( "A10", QVariant((int) 40000) );
doc2.write("A6", QVariant(QDateTime::currentDateTimeUtc()));
doc2.write("A7", QVariant(double(10.5)));
doc2.write("A8", QVariant(QDate(2019, 10, 9)));
doc2.write("A9", QVariant(QTime(10, 9, 5)));
doc2.write("A10", QVariant((int) 40000));
qDebug() << "doc2.read()";
qDebug() << doc2.read( 1, 1 ).type() << doc2.read( 1, 1 );
qDebug() << doc2.read( 2, 1 ).type() << doc2.read( 2, 1 );
qDebug() << doc2.read( 3, 1 ).type() << doc2.read( 3, 1 );
qDebug() << doc2.read( 4, 1 ).type() << doc2.read( 4, 1 );
qDebug() << doc2.read( 5, 1 ).type() << doc2.read( 5, 1 );
qDebug() << doc2.read( 6, 1 ).type() << doc2.read( 6, 1 );
qDebug() << doc2.read( 7, 1 ).type() << doc2.read( 7, 1 );
qDebug() << doc2.read( 8, 1 ).type() << doc2.read( 8, 1 );
qDebug() << doc2.read( 9, 1 ).type() << doc2.read( 9, 1 );
qDebug() << doc2.read(10, 1 ).type() << doc2.read(10, 1 );
qDebug() << doc2.read(1, 1).type() << doc2.read(1, 1);
qDebug() << doc2.read(2, 1).type() << doc2.read(2, 1);
qDebug() << doc2.read(3, 1).type() << doc2.read(3, 1);
qDebug() << doc2.read(4, 1).type() << doc2.read(4, 1);
qDebug() << doc2.read(5, 1).type() << doc2.read(5, 1);
qDebug() << doc2.read(6, 1).type() << doc2.read(6, 1);
qDebug() << doc2.read(7, 1).type() << doc2.read(7, 1);
qDebug() << doc2.read(8, 1).type() << doc2.read(8, 1);
qDebug() << doc2.read(9, 1).type() << doc2.read(9, 1);
qDebug() << doc2.read(10, 1).type() << doc2.read(10, 1);
qDebug() << "\n";
qDebug() << "doc2.cellAt()->value()";
qDebug() << doc2.cellAt( 1, 1 )->value().type() << doc2.cellAt( 1, 1 )->value();
qDebug() << doc2.cellAt( 2, 1 )->value().type() << doc2.cellAt( 2, 1 )->value();
qDebug() << doc2.cellAt( 3, 1 )->value().type() << doc2.cellAt( 3, 1 )->value();
qDebug() << doc2.cellAt( 4, 1 )->value().type() << doc2.cellAt( 4, 1 )->value();
qDebug() << doc2.cellAt( 5, 1 )->value().type() << doc2.cellAt( 5, 1 )->value();
qDebug() << doc2.cellAt( 6, 1 )->value().type() << doc2.cellAt( 6, 1 )->value();
qDebug() << doc2.cellAt( 7, 1 )->value().type() << doc2.cellAt( 7, 1 )->value();
qDebug() << doc2.cellAt( 8, 1 )->value().type() << doc2.cellAt( 8, 1 )->value();
qDebug() << doc2.cellAt( 9, 1 )->value().type() << doc2.cellAt( 9, 1 )->value();
qDebug() << doc2.cellAt(10, 1 )->value().type() << doc2.cellAt(10, 1 )->value();
qDebug() << doc2.cellAt(1, 1)->value().type() << doc2.cellAt(1, 1)->value();
qDebug() << doc2.cellAt(2, 1)->value().type() << doc2.cellAt(2, 1)->value();
qDebug() << doc2.cellAt(3, 1)->value().type() << doc2.cellAt(3, 1)->value();
qDebug() << doc2.cellAt(4, 1)->value().type() << doc2.cellAt(4, 1)->value();
qDebug() << doc2.cellAt(5, 1)->value().type() << doc2.cellAt(5, 1)->value();
qDebug() << doc2.cellAt(6, 1)->value().type() << doc2.cellAt(6, 1)->value();
qDebug() << doc2.cellAt(7, 1)->value().type() << doc2.cellAt(7, 1)->value();
qDebug() << doc2.cellAt(8, 1)->value().type() << doc2.cellAt(8, 1)->value();
qDebug() << doc2.cellAt(9, 1)->value().type() << doc2.cellAt(9, 1)->value();
qDebug() << doc2.cellAt(10, 1)->value().type() << doc2.cellAt(10, 1)->value();
doc2.saveAs("datetime2.xlsx");
qDebug() << "\n\ndoc3\n";
Document doc3("datetime2.xlsx");
if ( !doc3.load() )
{
qWarning() << "failed to load datetime2.xlsx" ;
if (!doc3.load()) {
qWarning() << "failed to load datetime2.xlsx";
return (-1);
}
qDebug() << "\n\n";
qDebug() << "doc3.read()";
qDebug() << doc3.read( 1, 1 ).type() << doc3.read( 1, 1 );
qDebug() << doc3.read( 2, 1 ).type() << doc3.read( 2, 1 );
qDebug() << doc3.read( 3, 1 ).type() << doc3.read( 3, 1 );
qDebug() << doc3.read( 4, 1 ).type() << doc3.read( 4, 1 );
qDebug() << doc3.read( 5, 1 ).type() << doc3.read( 5, 1 );
qDebug() << doc3.read( 6, 1 ).type() << doc3.read( 6, 1 );
qDebug() << doc3.read( 7, 1 ).type() << doc3.read( 7, 1 );
qDebug() << doc3.read( 8, 1 ).type() << doc3.read( 8, 1 );
qDebug() << doc3.read( 9, 1 ).type() << doc3.read( 9, 1 );
qDebug() << doc3.read(10, 1 ).type() << doc3.read(10, 1 );
qDebug() << doc3.read(1, 1).type() << doc3.read(1, 1);
qDebug() << doc3.read(2, 1).type() << doc3.read(2, 1);
qDebug() << doc3.read(3, 1).type() << doc3.read(3, 1);
qDebug() << doc3.read(4, 1).type() << doc3.read(4, 1);
qDebug() << doc3.read(5, 1).type() << doc3.read(5, 1);
qDebug() << doc3.read(6, 1).type() << doc3.read(6, 1);
qDebug() << doc3.read(7, 1).type() << doc3.read(7, 1);
qDebug() << doc3.read(8, 1).type() << doc3.read(8, 1);
qDebug() << doc3.read(9, 1).type() << doc3.read(9, 1);
qDebug() << doc3.read(10, 1).type() << doc3.read(10, 1);
qDebug() << "\n";
qDebug() << "doc3.cellAt()->value()";
qDebug() << doc3.cellAt( 1, 1 )->value().type() << doc3.cellAt( 1, 1 )->value();
qDebug() << doc3.cellAt( 2, 1 )->value().type() << doc3.cellAt( 2, 1 )->value();
qDebug() << doc3.cellAt( 3, 1 )->value().type() << doc3.cellAt( 3, 1 )->value();
qDebug() << doc3.cellAt( 4, 1 )->value().type() << doc3.cellAt( 4, 1 )->value();
qDebug() << doc3.cellAt( 5, 1 )->value().type() << doc3.cellAt( 5, 1 )->value();
qDebug() << doc3.cellAt( 6, 1 )->value().type() << doc3.cellAt( 6, 1 )->value();
qDebug() << doc3.cellAt( 7, 1 )->value().type() << doc3.cellAt( 7, 1 )->value();
qDebug() << doc3.cellAt( 8, 1 )->value().type() << doc3.cellAt( 8, 1 )->value();
qDebug() << doc3.cellAt( 9, 1 )->value().type() << doc3.cellAt( 9, 1 )->value();
qDebug() << doc3.cellAt(10, 1 )->value().type() << doc3.cellAt(10, 1 )->value();
qDebug() << doc3.cellAt(1, 1)->value().type() << doc3.cellAt(1, 1)->value();
qDebug() << doc3.cellAt(2, 1)->value().type() << doc3.cellAt(2, 1)->value();
qDebug() << doc3.cellAt(3, 1)->value().type() << doc3.cellAt(3, 1)->value();
qDebug() << doc3.cellAt(4, 1)->value().type() << doc3.cellAt(4, 1)->value();
qDebug() << doc3.cellAt(5, 1)->value().type() << doc3.cellAt(5, 1)->value();
qDebug() << doc3.cellAt(6, 1)->value().type() << doc3.cellAt(6, 1)->value();
qDebug() << doc3.cellAt(7, 1)->value().type() << doc3.cellAt(7, 1)->value();
qDebug() << doc3.cellAt(8, 1)->value().type() << doc3.cellAt(8, 1)->value();
qDebug() << doc3.cellAt(9, 1)->value().type() << doc3.cellAt(9, 1)->value();
qDebug() << doc3.cellAt(10, 1)->value().type() << doc3.cellAt(10, 1)->value();
doc2.saveAs("datetime2.xlsx");
return 0;
}

View File

@ -2,39 +2,33 @@
#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++)
{
_n = n;
_array = new T *[n];
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++)
{
delete [] _array[i];
for (int i = 0; i < _n; i++) {
delete[] _array[i];
}
delete [] _array;
delete[] _array;
}
protected:
@ -42,5 +36,4 @@ protected:
int _n;
};
#endif // DYNARRAY2D_H

View File

@ -6,27 +6,25 @@
#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)
{
// [1] set name of column
// [1] set name of column
m_colNames = colTitle;
m_roleCount = m_colNames.size();
m_colNames = colTitle;
m_roleCount = m_colNames.size();
// [2] set data
// [2] set data
for (int dc = 0; dc < data.size() ; dc++ )
{
VLIST vList = data.at(dc);
m_the_data.append( vList );
}
for (int dc = 0; dc < data.size(); dc++) {
VLIST vList = data.at(dc);
m_the_data.append(vList);
}
}
void XlsxTableModel::testData()
@ -42,9 +40,9 @@ void XlsxTableModel::testData()
// set name of column
m_colNames.append( QString( "COL1" ) );
m_colNames.append( QString( "COL2" ) );
m_colNames.append( QString( "COL3" ) );
m_colNames.append(QString("COL1"));
m_colNames.append(QString("COL2"));
m_colNames.append(QString("COL3"));
m_roleCount = m_colNames.size();
@ -54,51 +52,49 @@ void XlsxTableModel::testData()
list1.append(QVariant("Alpha"));
list1.append(QVariant(10));
list1.append(QVariant(100.0));
m_the_data.append( list1 );
m_the_data.append(list1);
VLIST list2;
list2.append(QVariant("Beta"));
list2.append(QVariant(20));
list2.append(QVariant(200.0));
m_the_data.append( list2 );
m_the_data.append(list2);
VLIST list3;
list3.append(QVariant("Gamma"));
list3.append(QVariant(30));
list3.append(QVariant(300.0));
m_the_data.append( list3 );
m_the_data.append(list3);
VLIST list4;
list4.append(QVariant("Delta"));
list4.append(QVariant(40));
list4.append(QVariant(400.0));
m_the_data.append( list4 );
m_the_data.append(list4);
}
int XlsxTableModel::rowCount(const QModelIndex& parent) const
int XlsxTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_the_data.size();
}
int XlsxTableModel::columnCount(const QModelIndex& parent) const
int XlsxTableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_roleCount;
}
QVariant XlsxTableModel::data(const QModelIndex& index, int role) const
QVariant XlsxTableModel::data(const QModelIndex &index, int role) const
{
// current column & row
int col = index.column();
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,32 +103,28 @@ 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++ )
{
int plusOneRole = (int)(Qt::UserRole);
plusOneRole = plusOneRole + 1;
cmpRole = plusOneRole + jc;
if ( role == cmpRole )
{
for (int jc = 0; jc < vList.size(); jc++) {
int plusOneRole = (int) (Qt::UserRole);
plusOneRole = plusOneRole + 1;
cmpRole = plusOneRole + jc;
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
<< ", value=" << ret.toString();
qDebug() << "data: "
<< " col=" << col << ", row=" << row << ", role=" << role << ", cmpRole=" << cmpRole
<< ", value=" << ret.toString();
return ret;
}
@ -141,11 +133,10 @@ 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() );
int roleNo = (Qt::UserRole + 1) + ic;
roles.insert(roleNo, strRole.toLatin1());
}
return roles;
@ -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 )
{
res[ i.key() ] = i.value();
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,13 +29,14 @@ 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);
public: // virtual function of parent object
int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE;
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
@ -44,10 +45,9 @@ protected:
void testData(); // test function.
protected:
QList<VLIST> m_the_data; // table cell data
QList<VLIST> m_the_data; // table cell data
QList<QString> m_colNames; // column name
quint32 m_roleCount; // role count (same as column count)
quint32 m_roleCount; // role count (same as column count)
};
#endif

View File

@ -4,116 +4,107 @@
// 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);
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QQmlContext* ctxt = engine.rootContext();
QQmlContext *ctxt = engine.rootContext();
QXlsx::Document xlsx( ":/test.xlsx" ); // load xlsx
if (!xlsx.load())
{
QXlsx::Document xlsx(":/test.xlsx"); // load xlsx
if (!xlsx.load()) {
qDebug() << "[ERROR] Failed to load xlsx";
return (-1);
}
QList<QString> colTitle; // list of column title
QList<QString> colTitle; // list of column title
QVector<CellLocation> vcl; // vector of cell(s) location
Worksheet* wsheet = (Worksheet*) xlsx.workbook()->activeSheet();
if ( NULL == wsheet )
{
Worksheet *wsheet = (Worksheet *) xlsx.workbook()->activeSheet();
if (NULL == wsheet) {
qDebug() << "[ERROR] Failed to get active sheet";
return (-2);
}
int rowMax = -1;
int colMax = -1;
vcl = wsheet->getFullCells( &rowMax, &colMax );
vcl = wsheet->getFullCells(&rowMax, &colMax);
Q_ASSERT( (-1) != rowMax ); // To CHECK
Q_ASSERT( (-1) != colMax );
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 );
QString colName = QString::fromStdString(strCol);
colTitle.append(colName);
}
// make cell matrix that has (colMax x rowMax) size.
DynArray2D< std::string > dynIntArray(colMax, rowMax);
DynArray2D<std::string> dynIntArray(colMax, rowMax);
for ( int icl = 0; icl < vcl.size(); ++icl )
{
CellLocation cl = vcl.at(icl); // cell location
for (int icl = 0; icl < vcl.size(); ++icl) {
CellLocation cl = vcl.at(icl); // cell location
// NOTICE: First cell of tableWidget is 0.
// But first cell of Qxlsx document is 1.
int row = cl.row - 1;
int col = cl.col - 1;
// NOTICE: First cell of tableWidget is 0.
// But first cell of Qxlsx document is 1.
int row = cl.row - 1;
int col = cl.col - 1;
auto ptrCell = cl.cell; // cell pointer
auto ptrCell = cl.cell; // cell pointer
// value of cell
QVariant var = ptrCell->value();
QString str = var.toString();
// value of cell
QVariant var = ptrCell->value();
QString str = var.toString();
// set string value to (col, row)
dynIntArray.setValue( col, row, str.toStdString() );
// set string value to (col, row)
dynIntArray.setValue(col, row, str.toStdString());
}
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++)
{
std::string value = dynIntArray.getValue( ic, ir );
vl.append( QString::fromStdString(value) );
for (int ic = 0; ic < colMax; ic++) {
std::string value = dynIntArray.getValue(ic, ir);
vl.append(QString::fromStdString(value));
}
xlsxData.append(vl);
}
// set model for tableview
XlsxTableModel xlsxTableModel(colTitle, xlsxData);
ctxt->setContextProperty( "xlsxModel", &xlsxTableModel );
ctxt->setContextProperty("xlsxModel", &xlsxTableModel);
engine.load( QUrl(QStringLiteral("qrc:/main.qml")) ); // load QML
if ( engine.rootObjects().isEmpty() )
{
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // load QML
if (engine.rootObjects().isEmpty()) {
qDebug() << "Failed to load qml";
return (-1);
}
@ -130,29 +121,26 @@ std::string convertFromNumberToExcelColumn(int n)
std::string stdString;
char str[1000]; // To store result (Excel column name)
int i = 0; // To store current index in str which is result
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
n = (n / 26) - 1;
} else // If remainder is non-zero
{
str[i++] = (rem-1) + 'A';
n = n / 26;
str[i++] = (rem - 1) + 'A';
n = n / 26;
}
}
str[i] = '\0';
// Reverse the string and print result
std::reverse( str, str + strlen(str) );
std::reverse(str, str + strlen(str));
stdString = str;
return stdString;

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,18 +30,17 @@ 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!");
xlsxW.write(row, col, writeValue);
if ( xlsxW.saveAs("Test.xlsx") ) // save the document as 'Test.xlsx'
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);
}
@ -51,25 +50,21 @@ int main(int argc, char *argv[])
//--------------------------------------
// [2] Reading excel file(*.xlsx)
Document xlsxR("Test.xlsx");
if ( xlsxR.load() ) // load excel file
Document xlsxR("Test.xlsx");
if (xlsxR.load()) // load excel file
{
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 ...)
Cell *cell = xlsxR.cellAt(row, col); // get cell pointer.
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;
@ -22,12 +22,11 @@ extern int test(QVector<QVariant> params);
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication app(argc, argv);
QVector<QVariant> testParams;
int ret = test(testParams);
QVector<QVariant> testParams;
int ret = test(testParams);
// qDebug() << "test return value : " << ret;
return 0;
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 <QColor>
#include <QImage>
#include <QRgb>
#include <QRandomGenerator>
#include <iostream>
#include <QColor>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QImage>
#include <QRandomGenerator>
#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"
int test162( QVector<QVariant> params )
int test162(QVector<QVariant> params)
{
using namespace QXlsx;
@ -31,22 +31,17 @@ int test162( QVector<QVariant> params )
xlsx.saveAs("image1.xlsx");
Document xlsx2("image1.xlsx");
qDebug() << "xlsx2" ;
qDebug() << "xlsx2";
qDebug() << " image count : " << xlsx.getImageCount();
xlsx2.saveAs("image2.xlsx");
return 0;
}
int test( QVector<QVariant> params )
int test(QVector<QVariant> params)
{
qDebug() << "[debug] current path : " << QDir::currentPath();
// return test162( params );
return 0;
}

View File

@ -30,11 +30,11 @@
extern "C" {
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
# include <windows.h>
#endif
/*
@ -49,75 +49,76 @@ extern "C" {
* 4 -> magenta
* 5 -> cyan
*/
int colorprintf(int color, const char *format, ...) {
int fcolor = -1, retval = -99;
va_list args;
int colorprintf(int color, const char *format, ...)
{
int fcolor = -1, retval = -99;
va_list args;
#ifdef _WIN32
if (color == 0) {
fcolor = FOREGROUND_RED;
} else if (color == 1) {
fcolor = FOREGROUND_GREEN;
} else if (color == 2) {
fcolor = FOREGROUND_RED | FOREGROUND_GREEN;
} else if (color == 3) {
fcolor = FOREGROUND_BLUE;
} else if (color == 4) {
fcolor = FOREGROUND_RED | FOREGROUND_BLUE;
} else if (color == 5) {
fcolor = FOREGROUND_GREEN | FOREGROUND_BLUE;
}
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
WORD wOldColorAttrs;
HANDLE hStdout;
if (fcolor != -1) {
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if ((hStdout == NULL) || (hStdout == INVALID_HANDLE_VALUE)) {
return -99;
}
if (GetConsoleScreenBufferInfo(hStdout, &csbiInfo) == 0) {
return -99;
}
wOldColorAttrs = csbiInfo.wAttributes;
if (SetConsoleTextAttribute(hStdout, fcolor | FOREGROUND_INTENSITY) == 0) {
return -99;
}
}
if (color == 0) {
fcolor = FOREGROUND_RED;
} else if (color == 1) {
fcolor = FOREGROUND_GREEN;
} else if (color == 2) {
fcolor = FOREGROUND_RED | FOREGROUND_GREEN;
} else if (color == 3) {
fcolor = FOREGROUND_BLUE;
} else if (color == 4) {
fcolor = FOREGROUND_RED | FOREGROUND_BLUE;
} else if (color == 5) {
fcolor = FOREGROUND_GREEN | FOREGROUND_BLUE;
}
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
WORD wOldColorAttrs;
HANDLE hStdout;
if (fcolor != -1) {
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if ((hStdout == NULL) || (hStdout == INVALID_HANDLE_VALUE)) {
return -99;
}
if (GetConsoleScreenBufferInfo(hStdout, &csbiInfo) == 0) {
return -99;
}
wOldColorAttrs = csbiInfo.wAttributes;
if (SetConsoleTextAttribute(hStdout, fcolor | FOREGROUND_INTENSITY) == 0) {
return -99;
}
}
#else
if (color == 0) {
fcolor = 1;
} else if (color == 1) {
fcolor = 2;
} else if (color == 2) {
fcolor = 3;
} else if (color == 3) {
fcolor = 4;
} else if (color == 4) {
fcolor = 5;
} else if (color == 5) {
fcolor = 6;
}
if (fcolor != -1 && printf("\033[1;3%dm", fcolor) < 0) {
return -99;
}
if (color == 0) {
fcolor = 1;
} else if (color == 1) {
fcolor = 2;
} else if (color == 2) {
fcolor = 3;
} else if (color == 3) {
fcolor = 4;
} else if (color == 4) {
fcolor = 5;
} else if (color == 5) {
fcolor = 6;
}
if (fcolor != -1 && printf("\033[1;3%dm", fcolor) < 0) {
return -99;
}
#endif
va_start(args, format);
if (!args) {
return -99;
}
retval = vprintf(format, args);
va_end(args);
if (fcolor != -1) {
va_start(args, format);
if (!args) {
return -99;
}
retval = vprintf(format, args);
va_end(args);
if (fcolor != -1) {
#ifdef _WIN32
if (SetConsoleTextAttribute(hStdout, wOldColorAttrs) == 0) {
return -99;
}
if (SetConsoleTextAttribute(hStdout, wOldColorAttrs) == 0) {
return -99;
}
#else
if (printf("\033[0m") < 0) {
return -99;
}
if (printf("\033[0m") < 0) {
return -99;
}
#endif
}
return retval;
}
return retval;
}
#ifdef __cplusplus

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;
@ -22,11 +22,10 @@ extern int test(QVector<QVariant> params);
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication app(argc, argv);
QVector<QVariant> testParams;
int ret = test(testParams);
QVector<QVariant> testParams;
int ret = test(testParams);
return 0;
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"
@ -30,21 +30,19 @@ using namespace std;
// #include "colorprintf.h" // https://github.com/VittGam/colorprintf
#endif
int test( QVector<QVariant> params );
int test(QVector<QVariant> params);
int test( QVector<QVariant> params )
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,17 +15,13 @@ class QXLSX_EXPORT AbstractOOXmlFile
Q_DECLARE_PRIVATE(AbstractOOXmlFile)
public:
enum CreateFlag
{
F_NewFromScratch,
F_LoadFromExists
};
enum CreateFlag { F_NewFromScratch, F_LoadFromExists };
public:
virtual ~AbstractOOXmlFile();
virtual void saveToXmlFile(QIODevice *device) const = 0;
virtual bool loadFromXmlFile(QIODevice *device) = 0;
virtual bool loadFromXmlFile(QIODevice *device) = 0;
virtual QByteArray saveToXmlData() const;
virtual bool loadFromXmlData(const QByteArray &data);

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
@ -15,11 +14,11 @@ class AbstractOOXmlFilePrivate
Q_DECLARE_PUBLIC(AbstractOOXmlFile)
public:
AbstractOOXmlFilePrivate(AbstractOOXmlFile* q, AbstractOOXmlFile::CreateFlag flag);
AbstractOOXmlFilePrivate(AbstractOOXmlFile *q, AbstractOOXmlFile::CreateFlag flag);
virtual ~AbstractOOXmlFilePrivate();
public:
QString filePathInPackage; //such as "xl/worksheets/sheet1.xml"
QString filePathInPackage; // such as "xl/worksheets/sheet1.xml"
Relationships *relationships;
AbstractOOXmlFile::CreateFlag flag;

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
@ -22,7 +22,7 @@ public:
public:
// NOTE: If all Qt compiler supports C++1x, recommend to use a 'class enum'.
enum SheetType { ST_WorkSheet, ST_ChartSheet, ST_DialogSheet, ST_MacroSheet };
enum SheetState { SS_Visible,SS_Hidden, SS_VeryHidden };
enum SheetState { SS_Visible, SS_Hidden, SS_VeryHidden };
public:
QString sheetName() const;

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
@ -26,7 +26,7 @@ class WorksheetPrivate;
class QXLSX_EXPORT Cell
{
Q_DECLARE_PRIVATE(Cell)
Q_DECLARE_PRIVATE(Cell)
private:
friend class Worksheet;
@ -43,38 +43,37 @@ public:
SharedStringType,
StringType,
CustomType, // custom or un-defined cell type
};
};
public:
Cell(const QVariant &data = QVariant(),
CellType type = NumberType,
const Format &format = Format(),
Worksheet *parent = nullptr,
qint32 styleIndex = (-1) );
Cell(const Cell * const cell);
CellType type = NumberType,
const Format &format = Format(),
Worksheet *parent = nullptr,
qint32 styleIndex = (-1));
Cell(const Cell *const cell);
~Cell();
public:
CellPrivate * const d_ptr; // See D-pointer and Q-pointer of Qt, for more information.
CellPrivate *const d_ptr; // See D-pointer and Q-pointer of Qt, for more information.
public:
CellType cellType() const;
QVariant value() const;
QVariant readValue() const;
Format format() const;
bool hasFormula() const;
CellFormula formula() const;
CellType cellType() const;
QVariant value() const;
QVariant readValue() const;
Format format() const;
bool isDateTime() const;
bool hasFormula() const;
CellFormula formula() const;
bool isDateTime() const;
QVariant dateTime() const; // QDateTime, QDate, QTime
bool isRichString() const;
bool isRichString() const;
qint32 styleNumber() const;
static bool isDateType(CellType cellType, const Format &format);
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
@ -20,10 +20,12 @@ class CellPrivate
Q_DECLARE_PUBLIC(Cell)
public:
CellPrivate(Cell *p);
CellPrivate(const CellPrivate * const cp);
CellPrivate(const CellPrivate *const cp);
public:
Worksheet *parent;
Cell *q_ptr;
public:
Cell::CellType cellType;
QVariant value;

View File

@ -24,14 +24,14 @@ public:
public:
CellFormula();
CellFormula(const char *formula, FormulaType type=NormalType);
CellFormula(const QString &formula, FormulaType type=NormalType);
CellFormula(const char *formula, FormulaType type = NormalType);
CellFormula(const QString &formula, FormulaType type = NormalType);
CellFormula(const QString &formula, const CellRange &ref, FormulaType type);
CellFormula(const CellFormula &other);
~CellFormula();
public:
CellFormula &operator =(const CellFormula &other);
CellFormula &operator=(const CellFormula &other);
bool isValid() const;
FormulaType formulaType() const;
@ -39,11 +39,12 @@ public:
CellRange reference() const;
int sharedIndex() const;
bool operator == (const CellFormula &formula) const;
bool operator != (const CellFormula &formula) const;
bool operator==(const CellFormula &formula) const;
bool operator!=(const CellFormula &formula) const;
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,15 +15,17 @@ 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();
QString formula; //formula contents
QString formula; // formula contents
CellFormula::FormulaType type;
CellRange reference;
bool ca; //Calculate Cell
int si; //Shared group index
bool ca; // Calculate Cell
int si; // Shared group index
};
QT_END_NAMESPACE_XLSX

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
@ -23,7 +23,7 @@ public:
CellRange(const CellRange &other);
~CellRange();
QString toString(bool row_abs=false, bool col_abs=false) const;
QString toString(bool row_abs = false, bool col_abs = false) const;
bool isValid() const;
inline void setFirstRow(int row) { top = row; }
inline void setLastRow(int row) { bottom = row; }
@ -40,23 +40,24 @@ public:
inline CellReference bottomLeft() const { return CellReference(bottom, left); }
inline CellReference bottomRight() const { return CellReference(bottom, right); }
inline void operator =(const CellRange &other)
inline void operator=(const CellRange &other)
{
top = other.top;
top = other.top;
bottom = other.bottom;
left = other.left;
right = other.right;
left = other.left;
right = other.right;
}
inline bool operator ==(const CellRange &other) const
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
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
@ -19,7 +19,7 @@ public:
CellReference(const CellReference &other);
~CellReference();
QString toString(bool row_abs=false, bool col_abs=false) const;
QString toString(bool row_abs = false, bool col_abs = false) const;
static CellReference fromString(const QString &cell);
bool isValid() const;
inline void setRow(int row) { _row = row; }
@ -27,14 +27,15 @@ public:
inline int row() const { return _row; }
inline int column() const { return _column; }
inline bool operator ==(const CellReference &other) const
inline bool operator==(const CellReference &other) const
{
return _row==other._row && _column==other._column;
return _row == other._row && _column == other._column;
}
inline bool operator !=(const CellReference &other) const
inline bool operator!=(const CellReference &other) const
{
return _row!=other._row || _column!=other._column;
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
@ -21,33 +21,52 @@ class QXLSX_EXPORT Chart : public AbstractOOXmlFile
{
Q_DECLARE_PRIVATE(Chart)
public:
enum ChartType { // 16 type of chart (ECMA 376)
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 };
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,30 +3,30 @@
#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
class XlsxSeries
{
public:
//At present, we care about number cell ranges only!
// At present, we care about number cell ranges only!
QString numberDataSource_numRef; // yval, val
QString axDataSource_numRef; // xval, cat
QString axDataSource_numRef; // xval, cat
QString headerH_numRef;
QString headerV_numRef;
bool swapHeader = false;
bool swapHeader = false;
};
class XlsxAxis
@ -34,23 +34,19 @@ 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())
public:
XlsxAxis() {}
XlsxAxis(Type t, XlsxAxis::AxisPos p, int id, int crossId, QString axisTitle = QString())
{
type = t;
type = t;
axisPos = p;
axisId = id;
axisId = id;
crossAx = crossId;
if ( !axisTitle.isEmpty() )
{
axisNames[ p ] = axisTitle;
if (!axisTitle.isEmpty()) {
axisNames[p] = axisTitle;
}
}
@ -59,7 +55,7 @@ public:
XlsxAxis::AxisPos axisPos;
int axisId;
int crossAx;
QMap< XlsxAxis::AxisPos, QString > axisNames;
QMap<XlsxAxis::AxisPos, QString> axisNames;
};
class ChartPrivate : public AbstractOOXmlFilePrivate
@ -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,25 +80,27 @@ 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);
bool loadXmlAxisSerAx(QXmlStreamReader &reader);
bool loadXmlAxisValAx(QXmlStreamReader &reader);
bool loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Scaling(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Overlay(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Scaling(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Title_Overlay(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(QXmlStreamReader &reader, XlsxAxis *axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, XlsxAxis *axis);
QString readSubTree(QXmlStreamReader &reader);
@ -118,29 +118,29 @@ public:
void saveXmlChartLegend(QXmlStreamWriter &writer) const;
protected:
void saveXmlAxisCatAx(QXmlStreamWriter &writer, XlsxAxis* axis) const;
void saveXmlAxisDateAx(QXmlStreamWriter &writer, XlsxAxis* axis) const;
void saveXmlAxisSerAx(QXmlStreamWriter &writer, XlsxAxis* axis) const;
void saveXmlAxisValAx(QXmlStreamWriter &writer, XlsxAxis* axis) const;
void saveXmlAxisCatAx(QXmlStreamWriter &writer, XlsxAxis *axis) const;
void saveXmlAxisDateAx(QXmlStreamWriter &writer, XlsxAxis *axis) const;
void saveXmlAxisSerAx(QXmlStreamWriter &writer, XlsxAxis *axis) const;
void saveXmlAxisValAx(QXmlStreamWriter &writer, XlsxAxis *axis) const;
void saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis* axis) const;
void saveXmlAxisEG_AxShared_Title(QXmlStreamWriter &writer, XlsxAxis* axis) const;
QString GetAxisPosString( XlsxAxis::AxisPos axisPos ) const;
QString GetAxisName(XlsxAxis* ptrXlsxAxis) const;
void saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis *axis) const;
void saveXmlAxisEG_AxShared_Title(QXmlStreamWriter &writer, XlsxAxis *axis) const;
QString GetAxisPosString(XlsxAxis::AxisPos axisPos) const;
QString GetAxisName(XlsxAxis *ptrXlsxAxis) const;
public:
Chart::ChartType chartType;
QList< std::shared_ptr<XlsxSeries> > seriesList;
QList< std::shared_ptr<XlsxAxis> > axisList;
QMap< XlsxAxis::AxisPos, QString > axisNames;
QList<std::shared_ptr<XlsxSeries>> seriesList;
QList<std::shared_ptr<XlsxAxis>> axisList;
QMap<XlsxAxis::AxisPos, QString> axisNames;
QString chartTitle;
AbstractSheet* sheet;
AbstractSheet *sheet;
Chart::ChartAxisPos legendPos;
bool legendOverlay;
bool majorGridlinesEnabled;
bool minorGridlinesEnabled;
QString layout; // only for storing a readed file
QString layout; // only for storing a readed file
};
QT_END_NAMESPACE_XLSX

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;
@ -19,8 +19,8 @@ class XlsxColor
{
public:
explicit XlsxColor(const QColor &color = QColor());
explicit XlsxColor(const QString &theme, const QString &tint=QString());
explicit XlsxColor (int index);
explicit XlsxColor(const QString &theme, const QString &tint = QString());
explicit XlsxColor(int index);
bool isThemeColor() const;
bool isIndexedColor() const;
@ -36,7 +36,7 @@ public:
static QColor fromARGBString(const QString &c);
static QString toARGBString(const QColor &c);
bool saveToXml(QXmlStreamWriter &writer, const QString &node=QString()) const;
bool saveToXml(QXmlStreamWriter &writer, const QString &node = QString()) const;
bool loadFromXml(QXmlStreamReader &reader);
private:
@ -44,12 +44,12 @@ private:
};
#if !defined(QT_NO_DATASTREAM)
QDataStream &operator<<(QDataStream &, const XlsxColor &);
QDataStream &operator>>(QDataStream &, XlsxColor &);
QDataStream &operator<<(QDataStream &, const XlsxColor &);
QDataStream &operator>>(QDataStream &, XlsxColor &);
#endif
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const XlsxColor &c);
QDebug operator<<(QDebug dbg, const XlsxColor &c);
#endif
QT_END_NAMESPACE_XLSX

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 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 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);
QList<CellRange> ranges() const;
@ -101,7 +112,7 @@ public:
void addRange(int firstRow, int firstCol, int lastRow, int lastCol);
void addRange(const CellRange &range);
//needed by QSharedDataPointer!!
// needed by QSharedDataPointer!!
ConditionalFormatting &operator=(const ConditionalFormatting &other);
private:
@ -110,7 +121,7 @@ private:
private:
bool saveToXml(QXmlStreamWriter &writer) const;
bool loadFromXml(QXmlStreamReader &reader, Styles* styles = NULL);
bool loadFromXml(QXmlStreamReader &reader, Styles *styles = NULL);
QSharedDataPointer<ConditionalFormattingPrivate> d;
};

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
@ -18,12 +18,14 @@ class XlsxCfVoData
{
public:
XlsxCfVoData()
:gte(true)
: gte(true)
{
}
XlsxCfVoData(ConditionalFormatting::ValueObjectType type, const QString &value, bool gte=true)
:type(type), value(value), gte(gte)
XlsxCfVoData(ConditionalFormatting::ValueObjectType type, const QString &value, bool gte = true)
: type(type)
, value(value)
, gte(gte)
{
}
@ -38,7 +40,7 @@ public:
enum Attribute {
A_type,
A_dxfId,
//A_priority,
// A_priority,
A_stopIfTrue,
A_aboveAverage,
A_percent,
@ -68,8 +70,9 @@ public:
};
XlsxCfRuleData()
:priority(1)
{}
: priority(1)
{
}
int priority;
Format dxfFormat;
@ -83,13 +86,13 @@ public:
ConditionalFormattingPrivate(const ConditionalFormattingPrivate &other);
~ConditionalFormattingPrivate();
void writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData& cfvo) const;
bool readCfVo(QXmlStreamReader &reader, XlsxCfVoData& cfvo);
void writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData &cfvo) const;
bool readCfVo(QXmlStreamReader &reader, XlsxCfVoData &cfvo);
bool readCfRule(QXmlStreamReader &reader, XlsxCfRuleData *cfRule, Styles *styles);
bool readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *cfRule);
bool readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *cfRule);
QList<std::shared_ptr<XlsxCfRuleData> >cfRules;
QList<std::shared_ptr<XlsxCfRuleData>> cfRules;
QList<CellRange> ranges;
};

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
@ -21,7 +21,7 @@ public:
void addDefault(const QString &key, const QString &value);
void addOverride(const QString &key, const QString &value);
//Convenient funcation for addOverride()
// Convenient funcation for addOverride()
void addDocPropCore();
void addDocPropApp();
void addStyles();
@ -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();
@ -81,8 +68,8 @@ public:
void setErrorStyle(ErrorStyle es);
void setFormula1(const QString &formula);
void setFormula2(const QString &formula);
void setErrorMessage(const QString &error, const QString &title=QString());
void setPromptMessage(const QString &prompt, const QString &title=QString());
void setErrorMessage(const QString &error, const QString &title = QString());
void setPromptMessage(const QString &prompt, const QString &title = QString());
void setAllowBlank(bool enable);
void setPromptMessageVisible(bool visible);
void setErrorMessageVisible(bool visible);
@ -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
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
@ -19,30 +19,30 @@ class QXLSX_EXPORT DateType
{
public:
DateType();
/*
DateType(bool is1904 = false);
DateType(double d, bool is1904 = false);
DateType(QDateTime qdt, bool is1904 = false);
DateType(QDate qd, bool is1904 = false);
DateType(QTime qt, bool is1904 = false);
public:
enum currentDateType { DateAndTimeType, OnlyDateType, OnlyTimeType };
public:
currentDateType getType();
bool getValue(QDateTime* pQdt);
bool getValue(QDate* pQd);
bool getValue(QTime* pQt);
bool getValue(double* pD);
/*
DateType(bool is1904 = false);
DateType(double d, bool is1904 = false);
DateType(QDateTime qdt, bool is1904 = false);
DateType(QDate qd, bool is1904 = false);
DateType(QTime qt, bool is1904 = false);
public:
enum currentDateType { DateAndTimeType, OnlyDateType, OnlyTimeType };
public:
currentDateType getType();
bool getValue(QDateTime* pQdt);
bool getValue(QDate* pQd);
bool getValue(QTime* pQt);
bool getValue(double* pD);
protected:
protected:
protected:
bool isSet;
double dValue;
bool is1904Type;
currentDateType dType;
*/
protected:
bool isSet;
double dValue;
bool is1904Type;
currentDateType dType;
*/
};
QT_END_NAMESPACE_XLSX
#endif
#endif

View File

@ -3,22 +3,22 @@
#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;
QT_BEGIN_NAMESPACE_XLSX
class DocPropsApp : public AbstractOOXmlFile
class DocPropsApp : public AbstractOOXmlFile
{
public:
DocPropsApp(CreateFlag flag);
void addPartTitle(const QString &title);
void addHeadingPair(const QString &name, int value);
@ -31,7 +31,7 @@ public:
private:
QStringList m_titlesOfPartsList;
QList<std::pair<QString, int> > m_headingPairsList;
QList<std::pair<QString, int>> m_headingPairsList;
QMap<QString, QString> m_properties;
};

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>
@ -21,7 +21,7 @@ public:
bool setProperty(const QString &name, const QString &value);
QString property(const QString &name) const;
QStringList propertyNames() const;
void saveToXmlFile(QIODevice *device) const override;
bool loadFromXmlFile(QIODevice *device) override;

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
@ -26,102 +26,105 @@ class DocumentPrivate;
class QXLSX_EXPORT Document : public QObject
{
Q_OBJECT
Q_OBJECT
Q_DECLARE_PRIVATE(Document) // D-Pointer. Qt classes have a Q_DECLARE_PRIVATE
// macro in the public class. The macro reads: qglobal.h
public:
explicit Document(QObject *parent = nullptr);
Document(const QString& xlsxName, QObject* parent = nullptr);
Document(QIODevice* device, QObject* parent = nullptr);
~Document();
explicit Document(QObject *parent = nullptr);
Document(const QString &xlsxName, QObject *parent = nullptr);
Document(QIODevice *device, QObject *parent = nullptr);
~Document();
bool write(const CellReference &cell, const QVariant &value, const Format &format = Format());
bool write(int row, int col, const QVariant &value, const Format &format = Format());
QVariant read(const CellReference &cell) const;
QVariant read(int row, int col) const;
bool write(const CellReference &cell, const QVariant &value, const Format &format=Format());
bool write(int row, int col, const QVariant &value, const Format &format=Format());
QVariant read(const CellReference &cell) const;
QVariant read(int row, int col) const;
int insertImage(int row, int col, const QImage &image);
bool getImage(int imageIndex, QImage& img);
bool getImage(int row, int col, QImage& img);
bool getImage(int imageIndex, QImage &img);
bool getImage(int row, int col, QImage &img);
uint getImageCount();
Chart *insertChart(int row, int col, const QSize &size);
bool mergeCells(const CellRange &range, const Format &format=Format());
bool unmergeCells(const CellRange &range);
bool setColumnWidth(const CellRange &range, double width);
bool setColumnFormat(const CellRange &range, const Format &format);
bool setColumnHidden(const CellRange &range, bool hidden);
bool setColumnWidth(int column, double width);
bool setColumnFormat(int column, const Format &format);
bool setColumnHidden(int column, bool hidden);
bool setColumnWidth(int colFirst, int colLast, double width);
bool setColumnFormat(int colFirst, int colLast, const Format &format);
bool setColumnHidden(int colFirst, int colLast, bool hidden);
double columnWidth(int column);
Format columnFormat(int column);
bool isColumnHidden(int column);
Chart *insertChart(int row, int col, const QSize &size);
bool setRowHeight(int row, double height);
bool setRowFormat(int row, const Format &format);
bool setRowHidden(int row, bool hidden);
bool setRowHeight(int rowFirst, int rowLast, double height);
bool setRowFormat(int rowFirst, int rowLast, const Format &format);
bool setRowHidden(int rowFirst, int rowLast, bool hidden);
bool mergeCells(const CellRange &range, const Format &format = Format());
bool unmergeCells(const CellRange &range);
double rowHeight(int row);
Format rowFormat(int row);
bool isRowHidden(int row);
bool setColumnWidth(const CellRange &range, double width);
bool setColumnFormat(const CellRange &range, const Format &format);
bool setColumnHidden(const CellRange &range, bool hidden);
bool setColumnWidth(int column, double width);
bool setColumnFormat(int column, const Format &format);
bool setColumnHidden(int column, bool hidden);
bool setColumnWidth(int colFirst, int colLast, double width);
bool setColumnFormat(int colFirst, int colLast, const Format &format);
bool setColumnHidden(int colFirst, int colLast, bool hidden);
bool groupRows(int rowFirst, int rowLast, bool collapsed = true);
bool groupColumns(int colFirst, int colLast, bool collapsed = true);
bool addDataValidation(const DataValidation &validation);
bool addConditionalFormatting(const ConditionalFormatting &cf);
double columnWidth(int column);
Format columnFormat(int column);
bool isColumnHidden(int column);
Cell *cellAt(const CellReference &cell) const;
Cell *cellAt(int row, int col) const;
bool setRowHeight(int row, double height);
bool setRowFormat(int row, const Format &format);
bool setRowHidden(int row, bool hidden);
bool setRowHeight(int rowFirst, int rowLast, double height);
bool setRowFormat(int rowFirst, int rowLast, const Format &format);
bool setRowHidden(int rowFirst, int rowLast, bool hidden);
bool defineName(const QString &name, const QString &formula,
const QString &comment=QString(), const QString &scope=QString());
double rowHeight(int row);
Format rowFormat(int row);
bool isRowHidden(int row);
CellRange dimension() const;
bool groupRows(int rowFirst, int rowLast, bool collapsed = true);
bool groupColumns(int colFirst, int colLast, bool collapsed = true);
QString documentProperty(const QString &name) const;
void setDocumentProperty(const QString &name, const QString &property);
QStringList documentPropertyNames() const;
bool addDataValidation(const DataValidation &validation);
bool addConditionalFormatting(const ConditionalFormatting &cf);
QStringList sheetNames() const;
bool addSheet(const QString &name = QString(),
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());
CellRange dimension() const;
QString documentProperty(const QString &name) const;
void setDocumentProperty(const QString &name, const QString &property);
QStringList documentPropertyNames() const;
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);
bool renameSheet(const QString &oldName, const QString &newName);
bool copySheet(const QString &srcName, const QString &distName = QString());
bool moveSheet(const QString &srcName, int distIndex);
bool deleteSheet(const QString &name);
bool selectSheet(const QString &name);
bool selectSheet(int index);
bool renameSheet(const QString &oldName, const QString &newName);
bool copySheet(const QString &srcName, const QString &distName = QString());
bool moveSheet(const QString &srcName, int distIndex);
bool deleteSheet(const QString &name);
Workbook *workbook() const;
AbstractSheet *sheet(const QString &sheetName) const;
AbstractSheet *currentSheet() const;
Worksheet *currentWorksheet() const;
Workbook *workbook() const;
AbstractSheet *sheet(const QString &sheetName) const;
AbstractSheet *currentSheet() const;
Worksheet *currentWorksheet() const;
bool save() const;
bool saveAs(const QString &xlsXname) const;
bool saveAs(QIODevice *device) const;
bool save() const;
bool saveAs(const QString &xlsXname) const;
bool saveAs(QIODevice *device) const;
// copy style from one xlsx file to other
static bool copyStyle(const QString &from, const QString &to);
// copy style from one xlsx file to other
static bool copyStyle(const QString &from, const QString &to);
bool isLoadPackage() const;
bool load() const; // equals to isLoadPackage()
bool isLoadPackage() const;
bool load() const; // equals to isLoadPackage()
bool changeimage(int filenoinmidea,QString newfile); // add by liufeijin20181025
bool changeimage(int filenoinmidea, QString newfile); // add by liufeijin20181025
bool autosizeColumnWidth(const CellRange &range);
bool autosizeColumnWidth(int column);
@ -129,13 +132,12 @@ public:
bool autosizeColumnWidth(void);
private:
QMap<int, int> getMaximalColumnWidth(int firstRow=1, int lastRow=INT_MAX);
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.
DocumentPrivate* const d_ptr;
DocumentPrivate *const d_ptr;
};
QT_END_NAMESPACE_XLSX

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
@ -23,17 +23,17 @@ public:
bool loadPackage(QIODevice *device);
bool savePackage(QIODevice *device) const;
// copy style from one xlsx file to other
static bool copyStyle(const QString &from, const QString &to);
// copy style from one xlsx file to other
static bool copyStyle(const QString &from, const QString &to);
Document *q_ptr;
const QString defaultPackageName; //default name when package name not specified
QString packageName; //name of the .xlsx file
const QString defaultPackageName; // default name when package name not specified
QString packageName; // name of the .xlsx file
QMap<QString, QString> documentProperties; //core, app and custom properties
QMap<QString, QString> documentProperties; // core, app and custom properties
QSharedPointer<Workbook> workbook;
std::shared_ptr<ContentTypes> contentTypes;
bool isLoad;
bool isLoad;
};
QT_END_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
@ -20,20 +20,19 @@ class Drawing;
class MediaFile;
class Chart;
//Helper class
struct XlsxMarker
{
XlsxMarker(){}
// Helper class
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();}
int col() const {return cell.y();}
int rowOff() const {return offset.width();}
int colOff() const {return offset.height();}
int row() const { return cell.x(); }
int col() const { return cell.y(); }
int rowOff() const { return offset.width(); }
int colOff() const { return offset.height(); }
QPoint cell;
QSize offset;
@ -42,24 +41,17 @@ 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();
void setObjectPicture(const QImage &img);
bool getObjectPicture(QImage &img);
void setObjectGraphicFrame(QSharedPointer<Chart> chart);
virtual bool loadFromXml(QXmlStreamReader &reader) = 0;
virtual bool loadFromXml(QXmlStreamReader &reader) = 0;
virtual void saveToXml(QXmlStreamWriter &writer) const = 0;
virtual int row() const;
@ -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,40 +86,40 @@ protected:
QSharedPointer<Chart> m_chartFile;
int m_id;
public:
int getm_id();
protected:
// liufeij {{
void setObjectShape(const QImage &img); // liufeij
// liufeij {{
void setObjectShape(const QImage &img); // liufeij
QString editASName;
QString editASName;
// below only for twocellanchor shape
QPoint posTA; // for shape liufeij 20181024
QSize extTA; // for shape liufeij 20181024
int rotWithShapeTA; //// for shape liufeij 20181024
int dpiTA; //// for shape liufeij 20181024
QString sp_textlink,sp_macro,sp_blip_cstate,sp_blip_rembed;
QPoint posTA; // for shape liufeij 20181024
QSize extTA; // for shape liufeij 20181024
int rotWithShapeTA; //// for shape liufeij 20181024
int dpiTA; //// for shape liufeij 20181024
QString sp_textlink, sp_macro, sp_blip_cstate, sp_blip_rembed;
// BELOW only for cxnSp shape
QString cxnSp_filpV,cxnSp_macro;
// belwo for cxnsp and sp
QString xsp_cNvPR_name,xsp_cNvPR_id; //x measns shape and cxnSp together using
QString xbwMode; // same as above
QString xIn_algn,xIn_cmpd,xIn_cap,xIn_w; //cxnSp only need xIn_w
QString xprstGeom_prst;
QString x_headEnd_w,x_headEnd_len,x_headEnd_tyep;
QString x_tailEnd_w,x_tailEnd_len,x_tailEnd_tyep;
QString Style_inref_idx,style_fillref_idx,style_effectref_idx,style_forntref_idx;
QString Style_inref_val,style_fillref_val,style_effectref_val,style_forntref_val;
// liufeij }}
// BELOW only for cxnSp shape
QString cxnSp_filpV, cxnSp_macro;
// belwo for cxnsp and sp
QString xsp_cNvPR_name, xsp_cNvPR_id; // x measns shape and cxnSp together using
QString xbwMode; // same as above
QString xIn_algn, xIn_cmpd, xIn_cap, xIn_w; // cxnSp only need xIn_w
QString xprstGeom_prst;
QString x_headEnd_w, x_headEnd_len, x_headEnd_tyep;
QString x_tailEnd_w, x_tailEnd_len, x_tailEnd_tyep;
QString Style_inref_idx, style_fillref_idx, style_effectref_idx, style_forntref_idx;
QString Style_inref_val, style_fillref_val, style_effectref_val, style_forntref_val;
// liufeij }}
};
class DrawingAbsoluteAnchor : public DrawingAnchor
{
public:
DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType=Unknown);
DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType = Unknown);
QPoint pos;
QSize ext;
@ -137,7 +131,7 @@ public:
class DrawingOneCellAnchor : public DrawingAnchor
{
public:
DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType=Unknown);
DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType = Unknown);
XlsxMarker from;
QSize ext;
@ -152,7 +146,7 @@ public:
class DrawingTwoCellAnchor : public DrawingAnchor
{
public:
DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType=Unknown);
DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType = Unknown);
XlsxMarker from;
XlsxMarker to;

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,
@ -200,16 +189,19 @@ public:
bool isValid() const;
bool isEmpty() const;
bool operator == (const Format &format) const;
bool operator != (const Format &format) const;
bool operator==(const Format &format) const;
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);
QVariant property(int propertyId, const QVariant &defaultValue = QVariant()) const;
void setProperty(int propertyId,
const QVariant &value,
const QVariant &clearValue = QVariant(),
bool detach = true);
void clearProperty(int propertyId);
bool hasProperty(int propertyId) const;
bool boolProperty(int propertyId, bool defaultValue=false) const;
int intProperty(int propertyId, int defaultValue=0) const;
bool boolProperty(int propertyId, bool defaultValue = false) const;
int intProperty(int propertyId, int defaultValue = 0) const;
double doubleProperty(int propertyId, double defaultValue = 0.0) const;
QString stringProperty(int propertyId, const QString &defaultValue = QString()) const;
QColor colorProperty(int propertyId, const QColor &defaultValue = QColor()) const;
@ -243,10 +235,11 @@ public:
void setFillIndex(int index);
void setXfIndex(int index);
void setDxfIndex(int index);
private:
friend class Styles;
friend class ::FormatTest;
friend QDebug operator<<(QDebug, const Format &f);
friend QDebug operator<<(QDebug, const Format &f);
int theme() const;
@ -254,7 +247,7 @@ private:
};
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const Format &f);
QDebug operator<<(QDebug dbg, const Format &f);
#endif
QT_END_NAMESPACE_XLSX

View File

@ -2,37 +2,36 @@
#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
{
FT_Invalid = 0,
FT_NumFmt = 0x01,
FT_Font = 0x02,
FT_Alignment = 0x04,
FT_Border = 0x08,
FT_Fill = 0x10,
enum FormatType {
FT_Invalid = 0,
FT_NumFmt = 0x01,
FT_Font = 0x02,
FT_Alignment = 0x04,
FT_Border = 0x08,
FT_Fill = 0x10,
FT_Protection = 0x20
};
enum Property {
P_STARTID,
//numFmt
// numFmt
P_NumFmt_Id,
P_NumFmt_FormatCode,
//font
// font
P_Font_STARTID,
P_Font_Size = P_Font_STARTID,
P_Font_Italic,
@ -51,7 +50,7 @@ public:
P_Font_Extend,
P_Font_ENDID,
//border
// border
P_Border_STARTID,
P_Border_LeftStyle = P_Border_STARTID,
P_Border_RightStyle,
@ -66,14 +65,14 @@ public:
P_Border_DiagonalType,
P_Border_ENDID,
//fill
// fill
P_Fill_STARTID,
P_Fill_Pattern = P_Fill_STARTID,
P_Fill_BgColor,
P_Fill_FgColor,
P_Fill_ENDID,
//alignment
// alignment
P_Alignment_STARTID,
P_Alignment_AlignH = P_Alignment_STARTID,
P_Alignment_AlignV,
@ -83,7 +82,7 @@ public:
P_Alignment_ShinkToFit,
P_Alignment_ENDID,
//protection
// protection
P_Protection_Locked,
P_Protection_Hidden,
@ -94,7 +93,7 @@ public:
FormatPrivate(const FormatPrivate &other);
~FormatPrivate();
bool dirty; //The key re-generation is need.
bool dirty; // The key re-generation is need.
QByteArray formatKey;
bool font_dirty;
@ -124,7 +123,6 @@ public:
QMap<int, QVariant> properties;
};
QT_END_NAMESPACE_XLSX
#endif

View File

@ -4,25 +4,25 @@
#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)
# define QXLSX_EXPORT Q_DECL_EXPORT
# if defined(QXlsx_EXPORTS)
# define QXLSX_EXPORT Q_DECL_EXPORT
# else
# define QXLSX_EXPORT Q_DECL_IMPORT
# endif
#else
# define QXLSX_EXPORT Q_DECL_IMPORT
#endif
#else
# define QXLSX_EXPORT
# define QXLSX_EXPORT
#endif
#define QT_BEGIN_NAMESPACE_XLSX namespace QXlsx {

View File

@ -5,8 +5,8 @@
#include "xlsxglobal.h"
#include <QString>
#include <QByteArray>
#include <QString>
QT_BEGIN_NAMESPACE_XLSX
@ -14,10 +14,10 @@ class MediaFile
{
public:
MediaFile(const QString &fileName);
MediaFile(const QByteArray &bytes, const QString &suffix, const QString &mimeType=QString());
MediaFile(const QByteArray &bytes, const QString &suffix, const QString &mimeType = QString());
public:
void set(const QByteArray &bytes, const QString &suffix, const QString &mimeType=QString());
void set(const QByteArray &bytes, const QString &suffix, const QString &mimeType = QString());
QString suffix() const;
QString mimeType() const;
QByteArray contents() const;

View File

@ -38,21 +38,20 @@
#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;
QString targetMode;
};
class Relationships
class Relationships
{
public:
Relationships();
@ -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,23 +25,24 @@
#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;
class RichString;
// qHash is a friend, but we can't use default arguments for friends (§8.3.6.4)
uint qHash(const RichString &rs, uint seed = 0) Q_DECL_NOTHROW;
uint qHash(const RichString &rs, uint seed = 0) Q_DECL_NOTHROW;
class QXLSX_EXPORT RichString
{
public:
RichString();
explicit RichString(const QString& text);
explicit RichString(const QString &text);
RichString(const RichString &other);
~RichString();
@ -60,26 +61,27 @@ 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);
friend bool operator!=(const RichString &rs1, const RichString &rs2);
friend bool operator<(const RichString &rs1, const RichString &rs2);
friend QDebug operator<<(QDebug dbg, const RichString &rs);
friend uint qHash(const RichString &rs, uint seed) Q_DECL_NOTHROW;
friend bool operator==(const RichString &rs1, const RichString &rs2);
friend bool operator!=(const RichString &rs1, const RichString &rs2);
friend bool operator<(const RichString &rs1, const RichString &rs2);
friend QDebug operator<<(QDebug dbg, const RichString &rs);
QSharedDataPointer<RichStringPrivate> d;
};
bool operator==(const RichString &rs1, const RichString &rs2);
bool operator!=(const RichString &rs1, const RichString &rs2);
bool operator<(const RichString &rs1, const RichString &rs2);
bool operator==(const RichString &rs1, const QString &rs2);
bool operator==(const QString &rs1, const RichString &rs2);
bool operator!=(const RichString &rs1, const QString &rs2);
bool operator!=(const QString &rs1, const RichString &rs2);
bool operator==(const RichString &rs1, const RichString &rs2);
bool operator!=(const RichString &rs1, const RichString &rs2);
bool operator<(const RichString &rs1, const RichString &rs2);
bool operator==(const RichString &rs1, const QString &rs2);
bool operator==(const QString &rs1, const RichString &rs2);
bool operator!=(const RichString &rs1, const QString &rs2);
bool operator!=(const QString &rs1, const RichString &rs2);
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const RichString &rs);
QDebug operator<<(QDebug dbg, const RichString &rs);
#endif
QT_END_NAMESPACE_XLSX

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)
{
}
@ -60,13 +61,13 @@ public:
int count;
};
class SharedStrings : public AbstractOOXmlFile
class SharedStrings : public AbstractOOXmlFile
{
public:
SharedStrings(CreateFlag flag);
int count() const;
bool isEmpty() const;
int addSharedString(const QString &string);
int addSharedString(const RichString &string);
void removeSharedString(const QString &string);
@ -82,13 +83,13 @@ public:
bool loadFromXmlFile(QIODevice *device) override;
private:
void readString(QXmlStreamReader &reader); // <si>
void readRichStringPart(QXmlStreamReader &reader, RichString &rich); // <r>
void readString(QXmlStreamReader &reader); // <si>
void readRichStringPart(QXmlStreamReader &reader, RichString &rich); // <r>
void readPlainStringPart(QXmlStreamReader &reader, RichString &rich); // <v>
Format readRichStringPart_rPr(QXmlStreamReader &reader);
void writeRichStringPart_rPr(QXmlStreamWriter &writer, const Format &format) const;
QHash<RichString, XlsxSharedStringInfo> m_stringTable; //for fast lookup
QHash<RichString, XlsxSharedStringInfo> m_stringTable; // for fast lookup
QList<RichString> m_stringList;
int m_stringCount;
};

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
{
XlsxFormatNumberData() : formatIndex(0) {}
struct XlsxFormatNumberData {
XlsxFormatNumberData()
: formatIndex(0)
{
}
int formatIndex;
QString formatString;
@ -70,9 +72,9 @@ class Styles : public AbstractOOXmlFile
public:
Styles(CreateFlag flag);
~Styles();
void addXfFormat(const Format &format, bool force=false);
void addXfFormat(const Format &format, bool force = false);
Format xfFormat(int idx) const;
void addDxfFormat(const Format &format, bool force=false);
void addDxfFormat(const Format &format, bool force = false);
Format dxfFormat(int idx) const;
void saveToXmlFile(QIODevice *device) const override;
@ -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);
@ -116,8 +124,8 @@ private:
bool readCellStyleXfs(QXmlStreamReader &reader);
QHash<QString, int> m_builtinNumFmtsHash;
QMap<int, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtIdMap;
QHash<QString, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtsHash;
QMap<int, QSharedPointer<XlsxFormatNumberData>> m_customNumFmtIdMap;
QHash<QString, QSharedPointer<XlsxFormatNumberData>> m_customNumFmtsHash;
int m_nextCustomNumFmtId;
QList<Format> m_fontsList;
QList<Format> m_fillsList;

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,31 +3,30 @@
#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
class CellReference;
bool parseXsdBoolean(const QString &value, bool defaultValue=false);
bool parseXsdBoolean(const QString &value, bool defaultValue = false);
QStringList splitPath(const QString &path);
QString getRelFilePath(const QString &filePath);
double datetimeToNumber(const QDateTime &dt, bool is1904=false);
QVariant datetimeFromNumber(double num, bool is1904=false);
double datetimeToNumber(const QDateTime &dt, bool is1904 = false);
QVariant datetimeFromNumber(double num, bool is1904 = false);
double timeToNumber(const QTime &t);
QString createSafeSheetName(const QString &nameProposal);
@ -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,34 +39,40 @@ 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());
bool copySheet(int index, const QString &newName = QString());
bool moveSheet(int srcIndex, int distIndex);
AbstractSheet *activeSheet() const;
bool setActiveSheet(int index);
// void addChart();
bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString());
// void addChart();
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;
void setStringsToNumbersEnabled(bool enable=true);
void setStringsToNumbersEnabled(bool enable = true);
bool isStringsToHyperlinksEnabled() const;
void setStringsToHyperlinksEnabled(bool enable=true);
void setStringsToHyperlinksEnabled(bool enable = true);
bool isHtmlToRichStringEnabled() const;
void setHtmlToRichStringEnabled(bool enable=true);
void setHtmlToRichStringEnabled(bool enable = true);
QString defaultDateFormat() const;
void setDefaultDateFormat(const QString &format);
//internal used member
void addMediaFile(std::shared_ptr<MediaFile> media, bool force=false);
QList<std::shared_ptr<MediaFile> > mediaFiles() const;
// internal used member
void addMediaFile(std::shared_ptr<MediaFile> media, bool force = false);
QList<std::shared_ptr<MediaFile>> mediaFiles() const;
void addChartFile(QSharedPointer<Chart> chartFile);
QList<QSharedPointer<Chart> > chartFiles() const;
QList<QSharedPointer<Chart>> chartFiles() const;
private:
friend class Worksheet;
@ -85,9 +91,11 @@ private:
Theme *theme();
QList<QImage> images();
QList<Drawing *> drawings();
QList<QSharedPointer<AbstractSheet> > getSheetsByTypes(AbstractSheet::SheetType type) const;
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,32 +3,37 @@
#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)
: sheetId(-1)
{
}
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;
QString comment;
//using internal sheetId, instead of the localSheetId(order in the workbook)
// using internal sheetId, instead of the localSheetId(order in the workbook)
int sheetId;
};
@ -39,13 +44,13 @@ public:
WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag);
QSharedPointer<SharedStrings> sharedStrings;
QList<QSharedPointer<AbstractSheet> > sheets;
QList<QSharedPointer<SimpleOOXmlFile> > externalLinks;
QList<QSharedPointer<AbstractSheet>> sheets;
QList<QSharedPointer<SimpleOOXmlFile>> externalLinks;
QStringList sheetNames;
QSharedPointer<Styles> styles;
QSharedPointer<Theme> theme;
QList<std::shared_ptr<MediaFile> > mediaFiles;
QList<QSharedPointer<Chart> > chartFiles;
QList<std::shared_ptr<MediaFile>> mediaFiles;
QList<QSharedPointer<Chart>> chartFiles;
QList<XlsxDefineNameData> definedNamesList;
bool strings_to_numbers_enabled;
@ -63,7 +68,7 @@ public:
int firstsheet;
int table_count;
//Used to generate new sheet name and id
// Used to generate new sheet name and id
int last_worksheet_index;
int last_chartsheet_index;
int last_sheet_id;

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,44 +51,78 @@ public:
~Worksheet();
public:
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());
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(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(int row, int column, const RichString &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(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(int row, int 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());
bool writeBlank(const CellReference &row_column, const Format &format = Format());
bool writeBlank(int row, int column, const Format &format = Format());
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 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(int row, int 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(int row, int 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(int row, int 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);
@ -97,19 +131,19 @@ public:
Cell *cellAt(int row, int column) const;
int insertImage(int row, int column, const QImage &image);
bool getImage(int imageIndex, QImage& img);
bool getImage(int row, int column, QImage& img);
bool getImage(int imageIndex, QImage &img);
bool getImage(int row, int column, QImage &img);
uint getImageCount();
Chart *insertChart(int row, int column, const QSize &size);
bool mergeCells(const CellRange &range, const Format &format=Format());
bool mergeCells(const CellRange &range, const Format &format = Format());
bool unmergeCells(const CellRange &range);
QList<CellRange> mergedCells() const;
bool setColumnWidth(const CellRange& range, double width);
bool setColumnFormat(const CellRange& range, const Format &format);
bool setColumnHidden(const CellRange& range, bool hidden);
bool setColumnWidth(const CellRange &range, double width);
bool setColumnFormat(const CellRange &range, const Format &format);
bool setColumnHidden(const CellRange &range, bool hidden);
bool setColumnWidth(int colFirst, int colLast, double width);
bool setColumnFormat(int colFirst, int colLast, const Format &format);
bool setColumnHidden(int colFirst, int colLast, bool hidden);
@ -118,9 +152,9 @@ public:
Format columnFormat(int column);
bool isColumnHidden(int column);
bool setRowHeight(int rowFirst,int rowLast, double height);
bool setRowFormat(int rowFirst,int rowLast, const Format &format);
bool setRowHidden(int rowFirst,int rowLast, bool hidden);
bool setRowHeight(int rowFirst, int rowLast, double height);
bool setRowFormat(int rowFirst, int rowLast, const Format &format);
bool setRowHidden(int rowFirst, int rowLast, bool hidden);
double rowHeight(int row);
Format rowFormat(int row);
@ -151,9 +185,9 @@ public:
void setOutlineSymbolsVisible(bool visible);
bool isWhiteSpaceVisible() const;
void setWhiteSpaceVisible(bool visible);
bool setStartPage(int spagen); //add by liufeijin20181028
bool setStartPage(int spagen); // add by liufeijin20181028
QVector<CellLocation> getFullCells(int* maxRow, int* maxCol);
QVector<CellLocation> getFullCells(int *maxRow, int *maxCol);
private:
void saveToXmlFile(QIODevice *device) const override;

View File

@ -3,76 +3,78 @@
#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;
QT_BEGIN_NAMESPACE_XLSX
const int XLSX_ROW_MAX = 1048576;
const int XLSX_ROW_MAX = 1048576;
const int XLSX_COLUMN_MAX = 16384;
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;
QString target; //For External link
QString target; // For External link
QString location;
QString display;
QString tooltip;
};
// ECMA-376 Part1 18.3.1.81
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 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) {
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 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)
{
}
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)
, collapsed(false)
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
{
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)
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)
{
}
double width;
@ -144,7 +146,7 @@ public:
~WorksheetPrivate();
public:
int checkDimensions(int row, int col, bool ignore_row=false, bool ignore_col=false);
int checkDimensions(int row, int col, bool ignore_row = false, bool ignore_col = false);
Format cellFormat(int row, int col) const;
QString generateDimensionString() const;
void calculateSpans() const;
@ -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;
@ -169,22 +174,22 @@ public:
void loadXmlSheetViews(QXmlStreamReader &reader);
void loadXmlHyperlinks(QXmlStreamReader &reader);
QList<QSharedPointer<XlsxRowInfo> > getRowInfoList(int rowFirst, int rowLast);
QList<QSharedPointer<XlsxColumnInfo> > getColumnInfoList(int colFirst, int colLast);
QList<QSharedPointer<XlsxRowInfo>> getRowInfoList(int rowFirst, int rowLast);
QList<QSharedPointer<XlsxColumnInfo>> getColumnInfoList(int colFirst, int colLast);
QList<int> getColumnIndexes(int colFirst, int colLast);
bool isColumnRangeValid(int colFirst, int colLast);
SharedStrings *sharedStrings() const;
public:
QMap<int, QMap<int, std::shared_ptr<Cell> > > cellTable;
QMap<int, QMap<int, std::shared_ptr<Cell>>> cellTable;
QMap<int, QMap<int, QString> > comments;
QMap<int, QMap<int, QSharedPointer<XlsxHyperlinkData> > > urlTable;
QMap<int, QMap<int, QString>> comments;
QMap<int, QMap<int, QSharedPointer<XlsxHyperlinkData>>> urlTable;
QList<CellRange> merges;
QMap<int, QSharedPointer<XlsxRowInfo> > rowsInfo;
QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfo;
QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfoHelper;
QMap<int, QSharedPointer<XlsxRowInfo>> rowsInfo;
QMap<int, QSharedPointer<XlsxColumnInfo>> colsInfo;
QMap<int, QSharedPointer<XlsxColumnInfo>> colsInfoHelper;
QList<DataValidation> dataValidationsList;
QList<ConditionalFormatting> conditionalFormattingList;
@ -226,7 +231,7 @@ public:
// header footer, liufeijin
QString MoodFooter;
QString ModdHeader;
QString MoodalignWithMargins; // add align 20190619
QString MoodalignWithMargins; // add align 20190619
XlsxSheetFormatProps sheetFormatProps;
@ -244,7 +249,6 @@ public:
QRegularExpression urlPattern;
private:
static double calculateColWidth(int characters);
};

View File

@ -3,19 +3,18 @@
#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;
QT_BEGIN_NAMESPACE_XLSX
class ZipReader
class ZipReader
{
public:
explicit ZipReader(const QString &fileName);

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,24 +1,28 @@
// 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()
{
if (relationships) {
delete relationships;
delete relationships;
}
}
@ -31,14 +35,13 @@ AbstractOOXmlFilePrivate::~AbstractOOXmlFilePrivate()
*/
AbstractOOXmlFile::AbstractOOXmlFile(CreateFlag flag)
:d_ptr(new AbstractOOXmlFilePrivate(this, flag))
: d_ptr(new AbstractOOXmlFilePrivate(this, flag))
{
}
AbstractOOXmlFile::AbstractOOXmlFile(AbstractOOXmlFilePrivate *d)
:d_ptr(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,23 +1,22 @@
// 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)
: AbstractOOXmlFilePrivate(p, flag)
{
type = AbstractSheet::ST_WorkSheet;
type = AbstractSheet::ST_WorkSheet;
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()->name = name;
d_func()->id = id;
d_func()->workbook = workbook;
}
/*!
* Returns the name of the sheet.
*/

View File

@ -1,30 +1,30 @@
// 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)
CellPrivate::CellPrivate(const CellPrivate *const cp)
: parent(cp->parent)
, cellType(cp->cellType)
, value(cp->value)
@ -33,7 +33,6 @@ CellPrivate::CellPrivate(const CellPrivate * const cp)
, richString(cp->richString)
, styleNumber(cp->styleNumber)
{
}
/*!
@ -58,27 +57,27 @@ CellPrivate::CellPrivate(const CellPrivate * const cp)
* Created by Worksheet only.
*/
// qint32 styleIndex = (-1)
Cell::Cell(const QVariant &data,
CellType type,
const Format &format,
Worksheet *parent,
qint32 styleIndex ) :
d_ptr(new CellPrivate(this))
Cell::Cell(const QVariant &data,
CellType type,
const Format &format,
Worksheet *parent,
qint32 styleIndex)
: d_ptr(new CellPrivate(this))
{
d_ptr->value = data;
d_ptr->cellType = type;
d_ptr->format = format;
d_ptr->parent = parent;
d_ptr->styleNumber = styleIndex;
d_ptr->value = data;
d_ptr->cellType = type;
d_ptr->format = format;
d_ptr->parent = parent;
d_ptr->styleNumber = styleIndex;
}
/*!
* \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;
d_ptr->q_ptr = this;
}
/*!
@ -86,8 +85,8 @@ Cell::Cell(const Cell * const cell):
*/
Cell::~Cell()
{
if ( NULL != d_ptr )
delete d_ptr;
if (NULL != d_ptr)
delete d_ptr;
}
/*!
@ -95,9 +94,9 @@ Cell::~Cell()
*/
Cell::CellType Cell::cellType() const
{
Q_D(const Cell);
Q_D(const Cell);
return d->cellType;
return d->cellType;
}
/*!
@ -105,72 +104,56 @@ Cell::CellType Cell::cellType() const
*/
QVariant Cell::value() const
{
Q_D(const Cell);
Q_D(const Cell);
return d->value;
return d->value;
}
/*!
* Return the data content of this Cell for reading
*/
* Return the data content of this Cell for reading
*/
QVariant Cell::readValue() const
{
Q_D(const Cell);
Q_D(const Cell);
QVariant ret; // return value
ret = d->value;
QVariant ret; // return value
ret = d->value;
Format fmt = this->format();
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 )
{
ret = vDT;
}
else if ( vDT.metaType().id() == QMetaType::QDate )
{
ret = vDT;
}
else if ( vDT.metaType().id() == QMetaType::QTime )
{
ret = vDT;
}
else
{
return QVariant();
}
#else
if ( vDT.type() == QVariant::DateTime )
{
ret = vDT;
}
else if ( vDT.type() == QVariant::Date )
{
ret = vDT;
}
else if ( vDT.type() == QVariant::Time )
{
ret = vDT;
}
else
{
return QVariant();
}
#endif
// 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) {
ret = vDT;
} else if (vDT.metaType().id() == QMetaType::QDate) {
ret = vDT;
} else if (vDT.metaType().id() == QMetaType::QTime) {
ret = vDT;
} else {
return QVariant();
}
#else
if (vDT.type() == QVariant::DateTime) {
ret = vDT;
} else if (vDT.type() == QVariant::Date) {
ret = vDT;
} else if (vDT.type() == QVariant::Time) {
ret = vDT;
} else {
return QVariant();
}
#endif
// QDateTime dt = dateTime();
// ret = dt;
// QString strFormat = fmt.numberFormat();
// if (!strFormat.isEmpty())
// {
@ -185,9 +168,9 @@ QVariant Cell::readValue() const
// if (styleNo == 11)
// {
// QTime timeValue = dt.time(); // only time. (HH:mm:ss)
// ret = timeValue;
// return ret;
// QTime timeValue = dt.time(); // only time. (HH:mm:ss)
// ret = timeValue;
// return ret;
// }
// if (styleNo == 12)
@ -196,42 +179,41 @@ QVariant Cell::readValue() const
// if (styleNo == 13) // (HH:mm:ss)
// {
// double dValue = d->value.toDouble();
// int day = int(dValue); // unit is day.
// double deciamlPointValue1 = dValue - double(day);
// double dValue = d->value.toDouble();
// int day = int(dValue); // unit is day.
// double deciamlPointValue1 = dValue - double(day);
// double dHour = deciamlPointValue1 * (double(1.0) / double(24.0));
// int hour = int(dHour);
// 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);
// int totalHour = hour + (day * 24);
// double deciamlPointValue3 = deciamlPointValue2 - (double(min) * (double(1.0) /
// double(60.0))); double dSec = deciamlPointValue3 * (double(1.0) / double(60.0)); int sec
// = int(dSec);
// QString strTime;
// strTime = QString("%1:%2:%3").arg(totalHour).arg(min).arg(sec);
// ret = strTime;
// int totalHour = hour + (day * 24);
// return ret;
// QString strTime;
// strTime = QString("%1:%2:%3").arg(totalHour).arg(min).arg(sec);
// ret = strTime;
// return ret;
// }
// return ret;
// */
}
}
if (hasFormula())
{
QString formulaString = this->formula().formulaText();
ret = formulaString;
return ret; // return formula string
}
if (hasFormula()) {
QString formulaString = this->formula().formulaText();
ret = formulaString;
return ret; // return formula string
}
return ret;
return ret;
}
/*!
@ -239,9 +221,9 @@ QVariant Cell::readValue() const
*/
Format Cell::format() const
{
Q_D(const Cell);
Q_D(const Cell);
return d->format;
return d->format;
}
/*!
@ -249,9 +231,9 @@ Format Cell::format() const
*/
bool Cell::hasFormula() const
{
Q_D(const Cell);
Q_D(const Cell);
return d->formula.isValid();
return d->formula.isValid();
}
/*!
@ -259,9 +241,9 @@ bool Cell::hasFormula() const
*/
CellFormula Cell::formula() const
{
Q_D(const Cell);
Q_D(const Cell);
return d->formula;
return d->formula;
}
/*!
@ -269,28 +251,22 @@ CellFormula Cell::formula() const
*/
bool Cell::isDateTime() const
{
Q_D(const Cell);
Q_D(const Cell);
Cell::CellType cellType = d->cellType;
double dValue = d->value.toDouble(); // number
// QString strValue = d->value.toString().toUtf8();
bool isValidFormat = d->format.isValid();
Cell::CellType cellType = d->cellType;
double dValue = d->value.toDouble(); // number
// QString strValue = d->value.toString().toUtf8();
bool isValidFormat = d->format.isValid();
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;
}
}
return false;
return false;
}
/*!
@ -299,29 +275,28 @@ bool Cell::isDateTime() const
/*
QDateTime Cell::dateTime() const
{
Q_D(const Cell);
Q_D(const Cell);
if (!isDateTime())
return QDateTime();
if (!isDateTime())
return QDateTime();
return datetimeFromNumber(d->value.toDouble(), d->parent->workbook()->isDate1904());
return datetimeFromNumber(d->value.toDouble(), d->parent->workbook()->isDate1904());
}
*/
QVariant Cell::dateTime() const
{
Q_D(const Cell);
if (!isDateTime())
{
if (!isDateTime()) {
return QVariant();
}
// dev57
QVariant ret;
double dValue = d->value.toDouble();
double dValue = d->value.toDouble();
bool isDate1904 = d->parent->workbook()->isDate1904();
ret = datetimeFromNumber(dValue, isDate1904);
ret = datetimeFromNumber(dValue, isDate1904);
return ret;
}
@ -330,35 +305,30 @@ QVariant Cell::dateTime() const
*/
bool Cell::isRichString() const
{
Q_D(const Cell);
Q_D(const Cell);
if ( d->cellType != SharedStringType &&
d->cellType != InlineStringType &&
d->cellType != StringType )
{
return false;
if (d->cellType != SharedStringType && d->cellType != InlineStringType &&
d->cellType != StringType) {
return false;
}
return d->richString.isRichString();
return d->richString.isRichString();
}
qint32 Cell::styleNumber() const
qint32 Cell::styleNumber() const
{
Q_D(const Cell);
Q_D(const Cell);
qint32 ret = d->styleNumber;
return ret;
qint32 ret = d->styleNumber;
return ret;
}
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;
return false;
}
QT_END_NAMESPACE_XLSX

View File

@ -1,40 +1,46 @@
// 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
// Remove the formula '=' sign if exists
if (formula.startsWith(QLatin1String("=")))
formula.remove(0,1);
formula.remove(0, 1);
else if (formula.startsWith(QLatin1String("{=")) && formula.endsWith(QLatin1String("}")))
formula = formula.mid(2, formula.length()-3);
formula = formula.mid(2, formula.length() - 3);
}
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
@ -56,41 +62,38 @@ CellFormulaPrivate::~CellFormulaPrivate()
*/
CellFormula::CellFormula()
{
//The d pointer is initialized with a null pointer
// The d pointer is initialized with a null pointer
}
/*!
* Creates a new formula with the given \a formula and \a type.
*/
CellFormula::CellFormula(const char *formula, FormulaType type)
:d(new CellFormulaPrivate(QString::fromLatin1(formula), CellRange(), type))
: d(new CellFormulaPrivate(QString::fromLatin1(formula), CellRange(), type))
{
}
/*!
* Creates a new formula with the given \a formula and \a type.
*/
CellFormula::CellFormula(const QString &formula, FormulaType type)
:d(new CellFormulaPrivate(formula, CellRange(), type))
: d(new CellFormulaPrivate(formula, CellRange(), type))
{
}
/*!
* Creates a new formula with the given \a formula, \a ref and \a type.
*/
CellFormula::CellFormula(const QString &formula, const CellRange &ref, FormulaType type)
:d(new CellFormulaPrivate(formula, ref, type))
: d(new CellFormulaPrivate(formula, ref, type))
{
}
/*!
Creates a new formula with the same attributes as the \a other formula.
*/
CellFormula::CellFormula(const CellFormula &other)
:d(other.d)
: d(other.d)
{
}
@ -98,7 +101,7 @@ CellFormula::CellFormula(const CellFormula &other)
Assigns the \a other formula to this formula, and returns a
reference to this formula.
*/
CellFormula &CellFormula::operator =(const CellFormula &other)
CellFormula &CellFormula::operator=(const CellFormula &other)
{
d = other.d;
return *this;
@ -107,10 +110,7 @@ CellFormula &CellFormula::operator =(const CellFormula &other)
/*!
* Destroys this formula.
*/
CellFormula::~CellFormula()
{
}
CellFormula::~CellFormula() {}
/*!
* Returns the type of the formula.
@ -187,7 +187,7 @@ int CellFormula::sharedIndex() const
*
* The possible values for this attribute are defined by the W3C XML Schema
* boolean datatype.
*/
*/
/* del2 (Input 2 Deleted) // not-impplmented attribute
*
@ -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
}
@ -365,23 +357,19 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader)
d = new CellFormulaPrivate(QString(), CellRange(), NormalType);
QXmlStreamAttributes attributes = reader.attributes();
QString typeString = attributes.value(QLatin1String("t")).toString();
QString typeString = attributes.value(QLatin1String("t")).toString();
// branch: shared-formula
//
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,14 +387,11 @@ 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);
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);
d->ca = parseXsdBoolean(ca, false);
if (attributes.hasAttribute(QLatin1String("si")))
{
if (attributes.hasAttribute(QLatin1String("si"))) {
d->si = attributes.value(QLatin1String("si")).toInt();
}
}
@ -435,19 +418,17 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader)
/*!
* \internal
*/
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;
}
/*!
* \internal
*/
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())
{
}
@ -69,16 +78,16 @@ void CellRange::init(const QString &range)
if (rs.size() == 2) {
CellReference start(rs[0]);
CellReference end(rs[1]);
top = start.row();
left = start.column();
top = start.row();
left = start.column();
bottom = end.row();
right = end.column();
right = end.column();
} else {
CellReference p(rs[0]);
top = p.row();
left = p.column();
top = p.row();
left = p.column();
bottom = p.row();
right = p.column();
right = p.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".
@ -107,7 +117,7 @@ QString CellRange::toString(bool row_abs, bool col_abs) const
return QString();
if (left == right && top == bottom) {
//Single cell
// Single cell
return CellReference(top, left).toString(row_abs, col_abs);
}

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;
int tmp = intPow(x, p / 2);
if (p % 2 == 0)
return tmp * tmp;
else
return x * tmp * tmp;
}
QString col_to_name(int col_num)
@ -32,7 +36,7 @@ QString col_to_name(int col_num)
remainder = col_num % 26;
if (remainder == 0)
remainder = 26;
col_str.prepend(QChar('A'+remainder-1));
col_str.prepend(QChar('A' + remainder - 1));
col_num = (col_num - 1) / 26;
}
it = col_cache.insert(col_num, col_str);
@ -43,16 +47,16 @@ QString col_to_name(int col_num)
int col_from_name(const QString &col_str)
{
int col = 0;
int col = 0;
int expn = 0;
for (int i=col_str.size()-1; i>-1; --i) {
for (int i = col_str.size() - 1; i > -1; --i) {
col += (col_str[i].unicode() - 'A' + 1) * intPow(26, expn);
expn++;
}
return col;
}
} //namespace
} // namespace
/*!
\class CellReference
@ -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)
{
}
@ -103,8 +109,8 @@ void CellReference::init(const QString &cell_str)
if (match.hasMatch()) {
const QString col_str = match.captured(1);
const QString row_str = match.captured(2);
_row = row_str.toInt();
_column = col_from_name(col_str);
_row = row_str.toInt();
_column = col_from_name(col_str);
}
}
@ -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
@ -35,15 +34,15 @@ ChartsheetPrivate::~ChartsheetPrivate()
* \internal
*/
Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFlag flag)
: AbstractSheet( name, id, workbook, new ChartsheetPrivate(this, flag) )
: AbstractSheet(name, id, workbook, new ChartsheetPrivate(this, flag))
{
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);
@ -64,7 +63,7 @@ Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFl
Chartsheet *Chartsheet::copy(const QString &distName, int distId) const
{
//:Todo
//: Todo
Q_UNUSED(distName)
Q_UNUSED(distId)
return 0;
@ -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,23 +92,28 @@ 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"));
writer.writeEmptyElement(QStringLiteral("sheetView"));
writer.writeAttribute(QStringLiteral("workbookViewId"), QString::number(0));
writer.writeAttribute(QStringLiteral("zoomToFit"), QStringLiteral("1"));
writer.writeEndElement(); //sheetViews
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.writeEndElement(); // chartsheet
writer.writeEndDocument();
}
@ -124,11 +126,11 @@ bool Chartsheet::loadFromXmlFile(QIODevice *device)
reader.readNextStartElement();
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("drawing")) {
QString rId = reader.attributes().value(QStringLiteral("r:id")).toString();
QString rId = reader.attributes().value(QStringLiteral("r:id")).toString();
QString name = d->relationships->getRelationshipById(rId).target;
const auto parts = splitPath(filePath());
QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name);
QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name);
d->drawing = std::make_shared<Drawing>(this, F_LoadFromExists);
d->drawing->setFilePath(path);

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)
@ -18,15 +18,13 @@ XlsxColor::XlsxColor(const QColor &color)
}
XlsxColor::XlsxColor(const QString &theme, const QString &tint)
:val(QStringList()<<theme<<tint)
: val(QStringList() << theme << tint)
{
}
XlsxColor::XlsxColor(int index)
:val(index)
: val(index)
{
}
bool XlsxColor::isRgbColor() const
@ -67,7 +65,7 @@ QStringList XlsxColor::themeColor() const
bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const
{
if (!node.isEmpty())
writer.writeEmptyElement(node); //color, bgColor, fgColor
writer.writeEmptyElement(node); // color, bgColor, fgColor
else
writer.writeEmptyElement(QStringLiteral("color"));
@ -89,34 +87,33 @@ bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const
bool XlsxColor::loadFromXml(QXmlStreamReader &reader)
{
const auto& attributes = reader.attributes();
const auto &attributes = reader.attributes();
if (attributes.hasAttribute(QLatin1String("rgb"))) {
const auto& colorString = attributes.value(QLatin1String("rgb")).toString();
const auto &colorString = attributes.value(QLatin1String("rgb")).toString();
val.setValue(fromARGBString(colorString));
} else if (attributes.hasAttribute(QLatin1String("indexed"))) {
int index = attributes.value(QLatin1String("indexed")).toInt();
val.setValue(index);
} else if (attributes.hasAttribute(QLatin1String("theme"))) {
const auto& theme = attributes.value(QLatin1String("theme")).toString();
const auto& tint = attributes.value(QLatin1String("tint")).toString();
val.setValue(QStringList()<<theme<<tint);
const auto &theme = attributes.value(QLatin1String("theme")).toString();
const auto &tint = attributes.value(QLatin1String("tint")).toString();
val.setValue(QStringList() << theme << tint);
}
return true;
}
XlsxColor::operator QVariant() const
{
const auto& cref
const auto &cref
#if QT_VERSION >= 0x060000 // Qt 6.0 or over
= QMetaType::fromType<XlsxColor>();
#else
= qMetaTypeId<XlsxColor>() ;
= qMetaTypeId<XlsxColor>();
#endif
return QVariant(cref, this);
}
QColor XlsxColor::fromARGBString(const QString &c)
{
QColor color;
@ -137,15 +134,15 @@ QString XlsxColor::toARGBString(const QColor &c)
QDataStream &operator<<(QDataStream &s, const XlsxColor &color)
{
if (color.isInvalid())
s<<0;
s << 0;
else if (color.isRgbColor())
s<<1<<color.rgbColor();
s << 1 << color.rgbColor();
else if (color.isIndexedColor())
s<<2<<color.indexedColor();
s << 2 << color.indexedColor();
else if (color.isThemeColor())
s<<3<<color.themeColor();
s << 3 << color.themeColor();
else
s<<4;
s << 4;
return s;
}
@ -153,20 +150,20 @@ QDataStream &operator<<(QDataStream &s, const XlsxColor &color)
QDataStream &operator>>(QDataStream &s, XlsxColor &color)
{
int marker(4);
s>>marker;
s >> marker;
if (marker == 0) {
color = XlsxColor();
} else if (marker == 1) {
QColor c;
s>>c;
s >> c;
color = XlsxColor(c);
} else if (marker == 2) {
int indexed;
s>>indexed;
s >> indexed;
color = XlsxColor(indexed);
} else if (marker == 3) {
QStringList list;
s>>list;
s >> list;
color = XlsxColor(list[0], list[1]);
}
@ -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)
: QSharedData(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;
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;
}
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
@ -118,18 +126,16 @@ void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const Xls
Construct a conditional formatting object
*/
ConditionalFormatting::ConditionalFormatting()
:d(new ConditionalFormattingPrivate())
: d(new ConditionalFormattingPrivate())
{
}
/*!
Constructs a copy of \a other.
*/
ConditionalFormatting::ConditionalFormatting(const ConditionalFormatting &other)
:d(other.d)
: 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,68 +174,90 @@ 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_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_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_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_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;
skipFormula = true;
} else if (type == Highlight_TimePeriod) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("timePeriod");
//:Todo
//: Todo
return false;
} else if (type == Highlight_Duplicate) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("duplicateValues");
} else if (type == Highlight_Unique) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("uniqueValues");
} else if (type == Highlight_Errors) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsErrors");
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsErrors");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(%1)");
skipFormula = true;
skipFormula = true;
} else if (type == Highlight_NoErrors) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsErrors");
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsErrors");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(%1))");
skipFormula = true;
skipFormula = true;
} else if (type == Highlight_Blanks) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsBlanks");
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsBlanks");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEN(TRIM(%1))=0");
skipFormula = true;
skipFormula = true;
} else if (type == Highlight_NoBlanks) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsBlanks");
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsBlanks");
cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEN(TRIM(%1))>0");
skipFormula = true;
skipFormula = true;
} else if (type >= Highlight_Top && type <= Highlight_BottomPercent) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("top10");
if (type == Highlight_Bottom || type == Highlight_BottomPercent)
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");
@ -242,7 +271,7 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const
cfRule->attrs[XlsxCfRuleData::A_stdDev] = QStringLiteral("2");
else if (type == Highlight_AboveStdDev3 || type == Highlight_BelowStdDev3)
cfRule->attrs[XlsxCfRuleData::A_stdDev] = QStringLiteral("3");
} else if (type == Highlight_Expression){
} else if (type == Highlight_Expression) {
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("expression");
} else {
return false;
@ -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,11 +331,17 @@ 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>();
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("dataBar");
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("dataBar");
cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(color);
if (stopIfTrue)
cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true;
@ -321,23 +363,26 @@ 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;
QString val1 = QStringLiteral("0");
QString val2 = QStringLiteral("0");
QString val1 = QStringLiteral("0");
QString val2 = QStringLiteral("0");
auto cfRule = std::make_shared<XlsxCfRuleData>();
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale");
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale");
cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor);
cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(maxColor);
if (stopIfTrue)
@ -356,18 +401,21 @@ 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;
ValueObjectType type3 = VOT_Max;
QString val1 = QStringLiteral("0");
QString val2 = QStringLiteral("50");
QString val3 = QStringLiteral("0");
QString val1 = QStringLiteral("0");
QString val2 = QStringLiteral("50");
QString val3 = QStringLiteral("0");
auto cfRule = std::make_shared<XlsxCfRuleData>();
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale");
cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale");
cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor);
cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(midColor);
cfRule->attrs[XlsxCfRuleData::A_color3] = XlsxColor(maxColor);
@ -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();
@ -444,19 +494,19 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu
}
rule->priority = attrs.value(QLatin1String("priority")).toInt();
if (attrs.value(QLatin1String("stopIfTrue")) == QLatin1String("1")) {
//default is false
// default is false
rule->attrs[XlsxCfRuleData::A_stopIfTrue] = QLatin1String("1");
}
if (attrs.value(QLatin1String("aboveAverage")) == QLatin1String("0")) {
//default is true
// default is true
rule->attrs[XlsxCfRuleData::A_aboveAverage] = QLatin1String("0");
}
if (attrs.value(QLatin1String("percent")) == QLatin1String("1")) {
//default is false
// default is false
rule->attrs[XlsxCfRuleData::A_percent] = QLatin1String("1");
}
if (attrs.value(QLatin1String("bottom")) == QLatin1String("1")) {
//default is false
// default is false
rule->attrs[XlsxCfRuleData::A_bottom] = QLatin1String("1");
}
if (attrs.hasAttribute(QLatin1String("operator")))
@ -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();
@ -475,7 +526,7 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu
rule->attrs[XlsxCfRuleData::A_stdDev] = attrs.value(QLatin1String("stdDev")).toString();
if (attrs.value(QLatin1String("equalAverage")) == QLatin1String("1")) {
//default is false
// default is false
rule->attrs[XlsxCfRuleData::A_equalAverage] = QLatin1String("1");
}
@ -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;
}
}
@ -590,13 +641,13 @@ bool ConditionalFormattingPrivate::readCfVo(QXmlStreamReader &reader, XlsxCfVoDa
t = ConditionalFormatting::VOT_Num;
else if (type == QLatin1String("percent"))
t = ConditionalFormatting::VOT_Percent;
else //if (type == QLatin1String("percentile"))
else // if (type == QLatin1String("percentile"))
t = ConditionalFormatting::VOT_Percentile;
cfvo.type = t;
cfvo.type = t;
cfvo.value = attrs.value(QLatin1String("val")).toString();
if (attrs.value(QLatin1String("gte")) == QLatin1String("0")) {
//default is true
// default is true
cfvo.gte = false;
}
return true;
@ -609,8 +660,8 @@ bool ConditionalFormatting::loadFromXml(QXmlStreamReader &reader, Styles *styles
d->ranges.clear();
d->cfRules.clear();
QXmlStreamAttributes attrs = reader.attributes();
const QString sqref = attrs.value(QLatin1String("sqref")).toString();
const auto sqrefParts = sqref.split(QLatin1Char(' '));
const QString sqref = attrs.value(QLatin1String("sqref")).toString();
const auto sqrefParts = sqref.split(QLatin1Char(' '));
for (const QString &range : sqrefParts) {
this->addRange(range);
}
@ -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;
}
@ -644,12 +694,14 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
}
writer.writeAttribute(QStringLiteral("sqref"), sqref.join(QLatin1String(" ")));
for (int i=0; i<d->cfRules.size(); ++i) {
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);
@ -699,7 +751,7 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo1].value<XlsxCfVoData>());
d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo2].value<XlsxCfVoData>());
rule->attrs[XlsxCfRuleData::A_color1].value<XlsxColor>().saveToXml(writer);
writer.writeEndElement();//dataBar
writer.writeEndElement(); // dataBar
} else if (rule->attrs[XlsxCfRuleData::A_type] == QLatin1String("colorScale")) {
writer.writeStartElement(QStringLiteral("colorScale"));
d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo1].value<XlsxCfVoData>());
@ -716,20 +768,21 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
if (it != rule->attrs.constEnd())
it.value().value<XlsxColor>().saveToXml(writer);
writer.writeEndElement();//colorScale
writer.writeEndElement(); // colorScale
}
it = rule->attrs.constFind(XlsxCfRuleData::A_formula1_temp);
if (it != rule->attrs.constEnd()) {
const auto _ranges = ranges();
const auto begin = _ranges.begin();
const auto begin = _ranges.begin();
if (begin != _ranges.end()) {
QString str = begin->toString();
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());
}
@ -741,10 +794,10 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
if (it != rule->attrs.constEnd())
writer.writeTextElement(QStringLiteral("formula"), it.value().toString());
writer.writeEndElement(); //cfRule
writer.writeEndElement(); // cfRule
}
writer.writeEndElement(); //conditionalFormatting
writer.writeEndElement(); // conditionalFormatting
return true;
}

View File

@ -1,23 +1,24 @@
// 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
ContentTypes::ContentTypes(CreateFlag flag)
:AbstractOOXmlFile(flag)
: AbstractOOXmlFile(flag)
{
m_package_prefix = QStringLiteral("application/vnd.openxmlformats-package.");
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,12 +117,13 @@ 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()
{
//:TODO
//: TODO
addOverride(QStringLiteral("bin"), QStringLiteral("application/vnd.ms-office.vbaProject"));
}
@ -123,33 +138,34 @@ 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);
while (it.hasNext()) {
it.next();
writer.writeStartElement(QStringLiteral("Default"));
writer.writeAttribute(QStringLiteral("Extension"), it.key());
writer.writeAttribute(QStringLiteral("ContentType"), it.value());
writer.writeEndElement();//Default
}
QMapIterator<QString, QString> it(m_defaults);
while (it.hasNext()) {
it.next();
writer.writeStartElement(QStringLiteral("Default"));
writer.writeAttribute(QStringLiteral("Extension"), it.key());
writer.writeAttribute(QStringLiteral("ContentType"), it.value());
writer.writeEndElement(); // Default
}
}
{
QMapIterator<QString, QString> it(m_overrides);
while (it.hasNext()) {
it.next();
writer.writeStartElement(QStringLiteral("Override"));
writer.writeAttribute(QStringLiteral("PartName"), it.key());
writer.writeAttribute(QStringLiteral("ContentType"), it.value());
writer.writeEndElement(); //Override
}
QMapIterator<QString, QString> it(m_overrides);
while (it.hasNext()) {
it.next();
writer.writeStartElement(QStringLiteral("Override"));
writer.writeAttribute(QStringLiteral("PartName"), it.key());
writer.writeAttribute(QStringLiteral("ContentType"), it.value());
writer.writeEndElement(); // Override
}
}
writer.writeEndElement();//Types
writer.writeEndElement(); // Types
writer.writeEndDocument();
}
bool ContentTypes::loadFromXmlFile(QIODevice *device)
@ -163,19 +179,19 @@ bool ContentTypes::loadFromXmlFile(QIODevice *device)
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("Default")) {
QXmlStreamAttributes attrs = reader.attributes();
QString extension = attrs.value(QLatin1String("Extension")).toString();
QString type = attrs.value(QLatin1String("ContentType")).toString();
QString extension = attrs.value(QLatin1String("Extension")).toString();
QString type = attrs.value(QLatin1String("ContentType")).toString();
m_defaults.insert(extension, type);
} else if (reader.name() == QLatin1String("Override")) {
QXmlStreamAttributes attrs = reader.attributes();
QString partName = attrs.value(QLatin1String("PartName")).toString();
QString type = attrs.value(QLatin1String("ContentType")).toString();
QString partName = attrs.value(QLatin1String("PartName")).toString();
QString type = attrs.value(QLatin1String("ContentType")).toString();
m_overrides.insert(partName, type);
}
}
if (reader.hasError()) {
qDebug()<<reader.errorString();
qDebug() << reader.errorString();
}
}
return true;

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)
: QSharedData(other)
, 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,28 +106,29 @@ 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)
:d(new DataValidationPrivate(type, op, formula1, formula2, allowBlank))
DataValidation::DataValidation(ValidationType type,
ValidationOperator op,
const QString &formula1,
const QString &formula2,
bool allowBlank)
: d(new DataValidationPrivate(type, op, formula1, formula2, allowBlank))
{
}
/*!
Construct a data validation object
*/
DataValidation::DataValidation()
:d(new DataValidationPrivate())
: d(new DataValidationPrivate())
{
}
/*!
Constructs a copy of \a other.
*/
DataValidation::DataValidation(const DataValidation &other)
:d(other.d)
: 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.
@ -291,7 +300,7 @@ void DataValidation::setFormula2(const QString &formula)
*/
void DataValidation::setErrorMessage(const QString &error, const QString &title)
{
d->errorMessage = error;
d->errorMessage = error;
d->errorMessageTitle = title;
}
@ -300,7 +309,7 @@ void DataValidation::setErrorMessage(const QString &error, const QString &title)
*/
void DataValidation::setPromptMessage(const QString &prompt, const QString &title)
{
d->promptMessage = prompt;
d->promptMessage = prompt;
d->promptMessageTitle = title;
}
@ -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)
@ -431,7 +437,7 @@ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const
if (!formula2().isEmpty())
writer.writeTextElement(QStringLiteral("formula2"), formula2());
writer.writeEndElement(); //dataValidation
writer.writeEndElement(); // dataValidation
return true;
}
@ -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,37 +467,36 @@ 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();
QString sqref = attrs.value(QLatin1String("sqref")).toString();
QString sqref = attrs.value(QLatin1String("sqref")).toString();
const auto sqrefParts = sqref.split(QLatin1Char(' '));
for (const QString &range : sqrefParts)
validation.addRange(range);
if (attrs.hasAttribute(QLatin1String("type"))) {
QString t = attrs.value(QLatin1String("type")).toString();
auto it = typeMap.constFind(t);
auto it = typeMap.constFind(t);
validation.setValidationType(it != typeMap.constEnd() ? it.value() : DataValidation::None);
}
if (attrs.hasAttribute(QLatin1String("errorStyle"))) {
QString es = attrs.value(QLatin1String("errorStyle")).toString();
auto it = esMap.constFind(es);
auto it = esMap.constFind(es);
validation.setErrorStyle(it != esMap.constEnd() ? it.value() : DataValidation::Stop);
}
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);
auto it = opMap.constFind(op);
validation.setValidationOperator(it != opMap.constEnd() ? it.value()
: DataValidation::Between);
}
if (attrs.hasAttribute(QLatin1String("allowBlank"))) {
validation.setAllowBlank(true);
@ -511,17 +515,18 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader)
}
QString et = attrs.value(QLatin1String("errorTitle")).toString();
QString e = attrs.value(QLatin1String("error")).toString();
QString e = attrs.value(QLatin1String("error")).toString();
if (!e.isEmpty() || !et.isEmpty())
validation.setErrorMessage(e, et);
QString pt = attrs.value(QLatin1String("promptTitle")).toString();
QString p = attrs.value(QLatin1String("prompt")).toString();
QString p = attrs.value(QLatin1String("prompt")).toString();
if (!p.isEmpty() || !pt.isEmpty())
validation.setPromptMessage(p, pt);
//find the end
while(!(reader.name() == QLatin1String("dataValidation") && reader.tokenType() == QXmlStreamReader::EndElement)) {
// find the end
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,18 +2,18 @@
#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
DocPropsApp::DocPropsApp(CreateFlag flag)
:AbstractOOXmlFile(flag)
: AbstractOOXmlFile(flag)
{
}
@ -24,14 +24,12 @@ void DocPropsApp::addPartTitle(const QString &title)
void DocPropsApp::addHeadingPair(const QString &name, int value)
{
m_headingPairsList.append({ name, value });
m_headingPairsList.append({name, 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"));
@ -73,19 +73,19 @@ void DocPropsApp::saveToXmlFile(QIODevice *device) const
writer.writeStartElement(QStringLiteral("HeadingPairs"));
writer.writeStartElement(vt, QStringLiteral("vector"));
writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size()*2));
writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size() * 2));
writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("variant"));
for (const auto &pair : m_headingPairsList) {
writer.writeStartElement(vt, QStringLiteral("variant"));
writer.writeTextElement(vt, QStringLiteral("lpstr"), pair.first);
writer.writeEndElement(); //vt:variant
writer.writeEndElement(); // vt:variant
writer.writeStartElement(vt, QStringLiteral("variant"));
writer.writeTextElement(vt, QStringLiteral("i4"), QString::number(pair.second));
writer.writeEndElement(); //vt:variant
writer.writeEndElement(); // vt:variant
}
writer.writeEndElement();//vt:vector
writer.writeEndElement();//HeadingPairs
writer.writeEndElement(); // vt:vector
writer.writeEndElement(); // HeadingPairs
writer.writeStartElement(QStringLiteral("TitlesOfParts"));
writer.writeStartElement(vt, QStringLiteral("vector"));
@ -93,22 +93,23 @@ void DocPropsApp::saveToXmlFile(QIODevice *device) const
writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("lpstr"));
for (const QString &title : m_titlesOfPartsList)
writer.writeTextElement(vt, QStringLiteral("lpstr"), title);
writer.writeEndElement();//vt:vector
writer.writeEndElement();//TitlesOfParts
writer.writeEndElement(); // vt:vector
writer.writeEndElement(); // TitlesOfParts
auto it = m_properties.constFind(QStringLiteral("manager"));
if (it != m_properties.constEnd())
writer.writeTextElement(QStringLiteral("Manager"), it.value());
//Not like "manager", "company" always exists for Excel generated file.
// 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"));
writer.writeTextElement(QStringLiteral("AppVersion"), QStringLiteral("12.0000"));
writer.writeEndElement(); //Properties
writer.writeEndElement(); // Properties
writer.writeEndDocument();
}
@ -116,21 +117,21 @@ bool DocPropsApp::loadFromXmlFile(QIODevice *device)
{
QXmlStreamReader reader(device);
while (!reader.atEnd()) {
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("Properties"))
continue;
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("Properties"))
continue;
if (reader.name() == QStringLiteral("Manager")) {
setProperty(QStringLiteral("manager"), reader.readElementText());
} else if (reader.name() == QStringLiteral("Company")) {
setProperty(QStringLiteral("company"), reader.readElementText());
}
}
if (reader.name() == QStringLiteral("Manager")) {
setProperty(QStringLiteral("manager"), reader.readElementText());
} else if (reader.name() == QStringLiteral("Company")) {
setProperty(QStringLiteral("company"), reader.readElementText());
}
}
if (reader.hasError()) {
qDebug("Error when read doc props app file.");
}
if (reader.hasError()) {
qDebug("Error when read doc props app file.");
}
}
return true;
}

View File

@ -1,31 +1,33 @@
// 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
DocPropsCore::DocPropsCore(CreateFlag flag)
:AbstractOOXmlFile(flag)
: AbstractOOXmlFile(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,11 +57,12 @@ 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 dc = QStringLiteral("http://purl.org/dc/elements/1.1/");
const QString dcterms = QStringLiteral("http://purl.org/dc/terms/");
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/");
const QString xsi = QStringLiteral("http://www.w3.org/2001/XMLSchema-instance");
const QString xsi = QStringLiteral("http://www.w3.org/2001/XMLSchema-instance");
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("cp:coreProperties"));
writer.writeNamespace(cp, QStringLiteral("cp"));
@ -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,18 +94,23 @@ 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.writeEndElement();//dcterms:created
writer.writeCharacters(it != m_properties.constEnd()
? it.value()
: QDateTime::currentDateTime().toString(Qt::ISODate));
writer.writeEndElement(); // dcterms:created
writer.writeStartElement(dcterms, QStringLiteral("modified"));
writer.writeAttribute(xsi, QStringLiteral("type"), QStringLiteral("dcterms:W3CDTF"));
writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate));
writer.writeEndElement();//dcterms:created
writer.writeEndElement(); // dcterms:created
it = m_properties.constFind(QStringLiteral("category"));
if (it != m_properties.constEnd())
@ -109,7 +120,7 @@ void DocPropsCore::saveToXmlFile(QIODevice *device) const
if (it != m_properties.constEnd())
writer.writeTextElement(cp, QStringLiteral("contentStatus"), it.value());
writer.writeEndElement(); //cp:coreProperties
writer.writeEndElement(); // cp:coreProperties
writer.writeEndDocument();
}
@ -117,58 +128,41 @@ bool DocPropsCore::loadFromXmlFile(QIODevice *device)
{
QXmlStreamReader reader(device);
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 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())
{
QXmlStreamReader::TokenType token = reader.readNext();
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();
const auto &nsUri = reader.namespaceUri();
const auto &name = reader.name();
if (name == QStringLiteral("subject") && nsUri == dc)
{
setProperty(QStringLiteral("subject"), reader.readElementText());
}
else if (name == QStringLiteral("title") && nsUri == dc)
{
setProperty(QStringLiteral("title"), reader.readElementText());
}
else if (name == QStringLiteral("creator") && nsUri == dc)
{
setProperty(QStringLiteral("creator"), reader.readElementText());
}
else if (name == QStringLiteral("description") && nsUri == dc)
{
setProperty(QStringLiteral("description"), reader.readElementText());
}
else if (name == QStringLiteral("keywords") && nsUri == cp)
{
setProperty(QStringLiteral("keywords"), reader.readElementText());
}
else if (name == QStringLiteral("created") && nsUri == dcterms)
{
setProperty(QStringLiteral("created"), reader.readElementText());
}
else if (name == QStringLiteral("category") && nsUri == cp)
{
setProperty(QStringLiteral("category"), reader.readElementText());
}
else if (name == QStringLiteral("contentStatus") && nsUri == cp)
{
setProperty(QStringLiteral("status"), reader.readElementText());
}
}
if (name == QStringLiteral("subject") && nsUri == dc) {
setProperty(QStringLiteral("subject"), reader.readElementText());
} else if (name == QStringLiteral("title") && nsUri == dc) {
setProperty(QStringLiteral("title"), reader.readElementText());
} else if (name == QStringLiteral("creator") && nsUri == dc) {
setProperty(QStringLiteral("creator"), reader.readElementText());
} else if (name == QStringLiteral("description") && nsUri == dc) {
setProperty(QStringLiteral("description"), reader.readElementText());
} else if (name == QStringLiteral("keywords") && nsUri == cp) {
setProperty(QStringLiteral("keywords"), reader.readElementText());
} else if (name == QStringLiteral("created") && nsUri == dcterms) {
setProperty(QStringLiteral("created"), reader.readElementText());
} else if (name == QStringLiteral("category") && nsUri == cp) {
setProperty(QStringLiteral("category"), reader.readElementText());
} else if (name == QStringLiteral("contentStatus") && nsUri == cp) {
setProperty(QStringLiteral("status"), reader.readElementText());
}
}
if (reader.hasError())
{
qDebug() << "Error when read doc props core file." << reader.errorString();
}
if (reader.hasError()) {
qDebug() << "Error when read doc props core file." << reader.errorString();
}
}
return true;
}

File diff suppressed because it is too large Load Diff

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,13 +31,16 @@ 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);
writer.writeEndElement();//xdr:wsDr
writer.writeEndElement(); // xdr:wsDr
writer.writeEndDocument();
}
@ -55,24 +59,20 @@ 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);
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);
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);
DrawingTwoCellAnchor *anchor = new DrawingTwoCellAnchor(this);
anchor->loadFromXml(reader);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,35 @@
// 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)
{
m_contents = bytes;
m_suffix = suffix;
m_mimeType = mimeType;
m_hashKey = QCryptographicHash::hash(m_contents, QCryptographicHash::Md5);
m_contents = bytes;
m_suffix = suffix;
m_mimeType = mimeType;
m_hashKey = QCryptographicHash::hash(m_contents, QCryptographicHash::Md5);
m_indexValid = false;
}
@ -66,7 +70,7 @@ bool MediaFile::isIndexValid() const
void MediaFile::setIndex(int idx)
{
m_index = idx;
m_index = idx;
m_indexValid = true;
}

View File

@ -2,8 +2,8 @@
#include "xlsxnumformatparser_p.h"
#include <QtGlobal>
#include <QString>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
@ -15,11 +15,11 @@ bool NumFormatParser::isDateTime(const QString &formatCode)
switch (c.unicode()) {
case '[':
// [h], [m], [s] are valid format for time
if (i < formatCode.length()-2 && formatCode[i+2] == QLatin1Char(']')) {
const QChar cc = formatCode[i+1].toLower();
if (i < formatCode.length() - 2 && formatCode[i + 2] == QLatin1Char(']')) {
const QChar cc = formatCode[i + 1].toLower();
if (cc == QLatin1Char('h') || cc == QLatin1Char('m') || cc == QLatin1Char('s'))
return true;
i+=2;
i += 2;
break;
} else {
// condition or color: don't care, ignore
@ -30,7 +30,7 @@ bool NumFormatParser::isDateTime(const QString &formatCode)
// quoted plain text block: don't care, ignore
case '"':
while (i < formatCode.length()-1 && formatCode[++i] != QLatin1Char('"'))
while (i < formatCode.length() - 1 && formatCode[++i] != QLatin1Char('"'))
;
break;

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,12 +71,14 @@ 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);
relation.type = type;
relation.target = target;
relation.id = QStringLiteral("rId%1").arg(m_relationships.size() + 1);
relation.type = type;
relation.target = target;
relation.targetMode = targetMode;
m_relationships.append(relation);
@ -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);
@ -96,7 +102,7 @@ void Relationships::saveToXmlFile(QIODevice *device) const
writer.writeAttribute(QStringLiteral("TargetMode"), relation.targetMode);
writer.writeEndElement();
}
writer.writeEndElement();//Relationships
writer.writeEndElement(); // Relationships
writer.writeEndDocument();
}
@ -115,20 +121,20 @@ bool Relationships::loadFromXmlFile(QIODevice *device)
clear();
QXmlStreamReader reader(device);
while (!reader.atEnd()) {
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QStringLiteral("Relationship")) {
QXmlStreamAttributes attributes = reader.attributes();
XlsxRelationship relationship;
relationship.id = attributes.value(QLatin1String("Id")).toString();
relationship.type = attributes.value(QLatin1String("Type")).toString();
relationship.target = attributes.value(QLatin1String("Target")).toString();
relationship.targetMode = attributes.value(QLatin1String("TargetMode")).toString();
m_relationships.append(relationship);
}
}
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QStringLiteral("Relationship")) {
QXmlStreamAttributes attributes = reader.attributes();
XlsxRelationship relationship;
relationship.id = attributes.value(QLatin1String("Id")).toString();
relationship.type = attributes.value(QLatin1String("Type")).toString();
relationship.target = attributes.value(QLatin1String("Target")).toString();
relationship.targetMode = attributes.value(QLatin1String("TargetMode")).toString();
m_relationships.append(relationship);
}
}
if (reader.hasError())
if (reader.hasError())
return false;
}
return true;

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)
: _dirty(true)
{
}
RichStringPrivate::RichStringPrivate(const RichStringPrivate &other)
:QSharedData(other), fragmentTexts(other.fragmentTexts)
,fragmentFormats(other.fragmentFormats)
, _idKey(other.idKey()), _dirty(other._dirty)
: QSharedData(other)
, fragmentTexts(other.fragmentTexts)
, fragmentFormats(other.fragmentFormats)
, _idKey(other.idKey())
, _dirty(other._dirty)
{
}
RichStringPrivate::~RichStringPrivate()
{
}
RichStringPrivate::~RichStringPrivate() {}
/*!
\class RichString
@ -40,15 +38,15 @@ RichStringPrivate::~RichStringPrivate()
Constructs a null string.
*/
RichString::RichString()
:d(new RichStringPrivate)
: d(new RichStringPrivate)
{
}
/*!
Constructs a plain string with the given \a text.
*/
RichString::RichString(const QString& text)
:d(new RichStringPrivate)
RichString::RichString(const QString &text)
: d(new RichStringPrivate)
{
addFragment(text, Format());
}
@ -57,23 +55,19 @@ RichString::RichString(const QString& text)
Constructs a copy of \a other.
*/
RichString::RichString(const RichString &other)
:d(other.d)
: d(other.d)
{
}
/*!
Destructs the string.
*/
RichString::~RichString()
{
}
RichString::~RichString() {}
/*!
Assigns \a other to this string and returns a reference to this string
*/
RichString &RichString::operator =(const RichString &other)
RichString &RichString::operator=(const RichString &other)
{
this->d = other.d;
return *this;
@ -84,11 +78,11 @@ RichString &RichString::operator =(const RichString &other)
*/
RichString::operator QVariant() const
{
const auto& cref
const auto &cref
#if QT_VERSION >= 0x060000 // Qt 6.0 or over
= QMetaType::fromType<RichString>();
#else
= qMetaTypeId<RichString>() ;
= qMetaTypeId<RichString>();
#endif
return QVariant(cref, this);
}
@ -98,7 +92,7 @@ RichString::operator QVariant() const
*/
bool RichString::isRichString() const
{
if (fragmentCount() > 1) //Is this enough??
if (fragmentCount() > 1) // Is this enough??
return true;
return false;
}
@ -116,7 +110,7 @@ bool RichString::isNull() const
*/
bool RichString::isEmtpy() const
{
for (const auto& str : d->fragmentTexts) {
for (const auto &str : d->fragmentTexts) {
if (!str.isEmpty())
return false;
}
@ -218,9 +212,9 @@ QByteArray RichStringPrivate::idKey() const
if (fragmentTexts.size() == 1) {
bytes = fragmentTexts[0].toUtf8();
} else {
//Generate a hash value base on QByteArray ?
// Generate a hash value base on QByteArray ?
bytes.append("@@QtXlsxRichString=");
for (int i=0; i<fragmentTexts.size(); ++i) {
for (int i = 0; i < fragmentTexts.size(); ++i) {
bytes.append("@Text");
bytes.append(fragmentTexts[i].toUtf8());
bytes.append("@Format");
@ -272,9 +266,9 @@ bool operator<(const RichString &rs1, const RichString &rs2)
Returns true if this string \a rs1 is equal to string \a rs2;
otherwise returns false.
*/
bool operator ==(const RichString &rs1, const QString &rs2)
bool operator==(const RichString &rs1, const QString &rs2)
{
if (rs1.fragmentCount() == 1 && rs1.fragmentText(0) == rs2) //format == 0
if (rs1.fragmentCount() == 1 && rs1.fragmentText(0) == rs2) // format == 0
return true;
return false;
@ -285,9 +279,9 @@ bool operator ==(const RichString &rs1, const QString &rs2)
Returns true if this string \a rs1 is not equal to string \a rs2;
otherwise returns false.
*/
bool operator !=(const RichString &rs1, const QString &rs2)
bool operator!=(const RichString &rs1, const QString &rs2)
{
if (rs1.fragmentCount() == 1 && rs1.fragmentText(0) == rs2) //format == 0
if (rs1.fragmentCount() == 1 && rs1.fragmentText(0) == rs2) // format == 0
return false;
return true;
@ -298,7 +292,7 @@ bool operator !=(const RichString &rs1, const QString &rs2)
Returns true if this string \a rs1 is equal to string \a rs2;
otherwise returns false.
*/
bool operator ==(const QString &rs1, const RichString &rs2)
bool operator==(const QString &rs1, const RichString &rs2)
{
return rs2 == rs1;
}
@ -308,14 +302,14 @@ bool operator ==(const QString &rs1, const RichString &rs2)
Returns true if this string \a rs1 is not equal to string \a rs2;
otherwise returns false.
*/
bool operator !=(const QString &rs1, const RichString &rs2)
bool operator!=(const QString &rs1, const RichString &rs2)
{
return rs2 != rs1;
}
uint qHash(const RichString &rs, uint seed) Q_DECL_NOTHROW
{
return qHash(rs.d->idKey(), seed);
return qHash(rs.d->idKey(), seed);
}
#ifndef QT_NO_DEBUG_STREAM

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
@ -25,7 +25,7 @@ QT_BEGIN_NAMESPACE_XLSX
*/
SharedStrings::SharedStrings(CreateFlag flag)
:AbstractOOXmlFile(flag)
: AbstractOOXmlFile(flag)
{
m_stringCount = 0;
}
@ -55,7 +55,7 @@ int SharedStrings::addSharedString(const RichString &string)
return it->index;
}
int index = m_stringList.size();
int index = m_stringList.size();
m_stringTable[string] = XlsxSharedStringInfo(index);
m_stringList.append(string);
return index;
@ -63,7 +63,7 @@ int SharedStrings::addSharedString(const RichString &string)
void SharedStrings::incRefByStringIndex(int idx)
{
if (idx <0 || idx >= m_stringList.size()) {
if (idx < 0 || idx >= m_stringList.size()) {
qDebug("SharedStrings: invlid index");
return;
}
@ -93,7 +93,7 @@ void SharedStrings::removeSharedString(const RichString &string)
it->count -= 1;
if (it->count <= 0) {
for (int i=it->index+1; i<m_stringList.size(); ++i)
for (int i = it->index + 1; i < m_stringList.size(); ++i)
m_stringTable[m_stringList[i]].index -= 1;
m_stringList.removeAt(it->index);
@ -145,7 +145,7 @@ void SharedStrings::writeRichStringPart_rPr(QXmlStreamWriter &writer, const Form
Format::FontUnderline u = format.fontUnderline();
if (u != Format::FontUnderlineNone) {
writer.writeEmptyElement(QStringLiteral("u"));
if (u== Format::FontUnderlineDouble)
if (u == Format::FontUnderlineDouble)
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("double"));
else if (u == Format::FontUnderlineSingleAccounting)
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("singleAccounting"));
@ -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));
}
}
@ -194,35 +196,37 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const
QXmlStreamWriter writer(device);
if (m_stringList.size() != m_stringTable.size()) {
//Duplicated string items exist in m_stringList
//Clean up can not be done here, as the indices
//have been used when we save the worksheets part.
// Duplicated string items exist in m_stringList
// Clean up can not be done here, as the indices
// have been used when we save the worksheets part.
}
writer.writeStartDocument(QStringLiteral("1.0"), true);
writer.writeStartElement(QStringLiteral("sst"));
writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
writer.writeAttribute(
QStringLiteral("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()));
for (const RichString &string : m_stringList) {
writer.writeStartElement(QStringLiteral("si"));
if (string.isRichString()) {
//Rich text string
for (int i=0; i<string.fragmentCount(); ++i) {
// Rich text string
for (int i = 0; i < string.fragmentCount(); ++i) {
writer.writeStartElement(QStringLiteral("r"));
if (string.fragmentFormat(i).hasFontData()) {
writer.writeStartElement(QStringLiteral("rPr"));
writeRichStringPart_rPr(writer, string.fragmentFormat(i));
writer.writeEndElement();// rPr
writer.writeEndElement(); // rPr
}
writer.writeStartElement(QStringLiteral("t"));
if (isSpaceReserveNeeded(string.fragmentText(i)))
writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
writer.writeCharacters(string.fragmentText(i));
writer.writeEndElement();// t
writer.writeEndElement(); // t
writer.writeEndElement(); //r
writer.writeEndElement(); // r
}
} else {
writer.writeStartElement(QStringLiteral("t"));
@ -230,12 +234,12 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const
if (isSpaceReserveNeeded(pString))
writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
writer.writeCharacters(pString);
writer.writeEndElement();//t
writer.writeEndElement(); // t
}
writer.writeEndElement();//si
writer.writeEndElement(); // si
}
writer.writeEndElement(); //sst
writer.writeEndElement(); // sst
writer.writeEndDocument();
}
@ -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"))
@ -255,7 +260,7 @@ void SharedStrings::readString(QXmlStreamReader &reader)
}
}
int idx = m_stringList.size();
int idx = m_stringList.size();
m_stringTable[richString] = XlsxSharedStringInfo(idx, 0);
m_stringList.append(richString);
}
@ -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")) {
@ -283,9 +289,9 @@ void SharedStrings::readPlainStringPart(QXmlStreamReader &reader, RichString &ri
{
Q_ASSERT(reader.name() == QLatin1String("t"));
//QXmlStreamAttributes attributes = reader.attributes();
// QXmlStreamAttributes attributes = reader.attributes();
// NOTICE: CHECK POINT
// NOTICE: CHECK POINT
QString text = reader.readElementText();
richString.addFragment(text, Format());
}
@ -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());
}
}
}
@ -351,19 +363,19 @@ Format SharedStrings::readRichStringPart_rPr(QXmlStreamReader &reader)
bool SharedStrings::loadFromXmlFile(QIODevice *device)
{
QXmlStreamReader reader(device);
int count = 0;
bool hasUniqueCountAttr=true;
int count = 0;
bool hasUniqueCountAttr = true;
while (!reader.atEnd()) {
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("sst")) {
QXmlStreamAttributes attributes = reader.attributes();
if ((hasUniqueCountAttr = attributes.hasAttribute(QLatin1String("uniqueCount"))))
count = attributes.value(QLatin1String("uniqueCount")).toInt();
} else if (reader.name() == QLatin1String("si")) {
readString(reader);
}
}
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("sst")) {
QXmlStreamAttributes attributes = reader.attributes();
if ((hasUniqueCountAttr = attributes.hasAttribute(QLatin1String("uniqueCount"))))
count = attributes.value(QLatin1String("uniqueCount")).toInt();
} else if (reader.name() == QLatin1String("si")) {
readString(reader);
}
}
}
if (hasUniqueCountAttr && m_stringList.size() != count) {
@ -372,8 +384,8 @@ bool SharedStrings::loadFromXmlFile(QIODevice *device)
}
if (m_stringList.size() != m_stringTable.size()) {
//qDebug("Warning: Duplicated items exist in shared string table.");
//Nothing we can do here, as indices of the strings will be used when loading sheets.
// qDebug("Warning: Duplicated items exist in shared string table.");
// Nothing we can do here, as indices of the strings will be used when loading sheets.
}
return true;

View File

@ -2,13 +2,13 @@
#include "xlsxsimpleooxmlfile_p.h"
#include <QtGlobal>
#include <QIODevice>
#include <QtGlobal>
QT_BEGIN_NAMESPACE_XLSX
SimpleOOXmlFile::SimpleOOXmlFile(CreateFlag flag)
:AbstractOOXmlFile(flag)
: AbstractOOXmlFile(flag)
{
}

File diff suppressed because it is too large Load Diff

View File

@ -7,181 +7,198 @@
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:themeElements>"
"<a:clrScheme name=\"Office\">"
"<a:dk1><a:sysClr val=\"windowText\" lastClr=\"000000\"/></a:dk1>"
"<a:lt1><a:sysClr val=\"window\" lastClr=\"FFFFFF\"/></a:lt1>"
"<a:dk2><a:srgbClr val=\"1F497D\"/></a:dk2>"
"<a:lt2><a:srgbClr val=\"EEECE1\"/></a:lt2>"
"<a:accent1><a:srgbClr val=\"4F81BD\"/></a:accent1>"
"<a:accent2><a:srgbClr val=\"C0504D\"/></a:accent2>"
"<a:accent3><a:srgbClr val=\"9BBB59\"/></a:accent3>"
"<a:accent4><a:srgbClr val=\"8064A2\"/></a:accent4>"
"<a:accent5><a:srgbClr val=\"4BACC6\"/></a:accent5>"
"<a:accent6><a:srgbClr val=\"F79646\"/></a:accent6>"
"<a:hlink><a:srgbClr val=\"0000FF\"/></a:hlink>"
"<a:folHlink><a:srgbClr val=\"800080\"/></a:folHlink>"
"</a:clrScheme>"
"<a:fontScheme name=\"Office\">"
"<a:majorFont>"
"<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=\"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\"/>"
"<a:font script=\"Arab\" typeface=\"Times New Roman\"/>"
"<a:font script=\"Hebr\" typeface=\"Times New Roman\"/>"
"<a:font script=\"Thai\" typeface=\"Tahoma\"/>"
"<a:font script=\"Ethi\" typeface=\"Nyala\"/>"
"<a:font script=\"Beng\" typeface=\"Vrinda\"/>"
"<a:font script=\"Gujr\" typeface=\"Shruti\"/>"
"<a:font script=\"Khmr\" typeface=\"MoolBoran\"/>"
"<a:font script=\"Knda\" typeface=\"Tunga\"/>"
"<a:font script=\"Guru\" typeface=\"Raavi\"/>"
"<a:font script=\"Cans\" typeface=\"Euphemia\"/>"
"<a:font script=\"Cher\" typeface=\"Plantagenet Cherokee\"/>"
"<a:font script=\"Yiii\" typeface=\"Microsoft Yi Baiti\"/>"
"<a:font script=\"Tibt\" typeface=\"Microsoft Himalaya\"/>"
"<a:font script=\"Thaa\" typeface=\"MV Boli\"/>"
"<a:font script=\"Deva\" typeface=\"Mangal\"/>"
"<a:font script=\"Telu\" typeface=\"Gautami\"/>"
"<a:font script=\"Taml\" typeface=\"Latha\"/>"
"<a:font script=\"Syrc\" typeface=\"Estrangelo Edessa\"/>"
"<a:font script=\"Orya\" typeface=\"Kalinga\"/>"
"<a:font script=\"Mlym\" typeface=\"Kartika\"/>"
"<a:font script=\"Laoo\" typeface=\"DokChampa\"/>"
"<a:font script=\"Sinh\" typeface=\"Iskoola Pota\"/>"
"<a:font script=\"Mong\" typeface=\"Mongolian Baiti\"/>"
"<a:font script=\"Viet\" typeface=\"Times New Roman\"/>"
"<a:font script=\"Uigh\" typeface=\"Microsoft Uighur\"/>"
"</a:majorFont>"
"<a:minorFont>"
"<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=\"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\"/>"
"<a:font script=\"Arab\" typeface=\"Arial\"/>"
"<a:font script=\"Hebr\" typeface=\"Arial\"/>"
"<a:font script=\"Thai\" typeface=\"Tahoma\"/>"
"<a:font script=\"Ethi\" typeface=\"Nyala\"/>"
"<a:font script=\"Beng\" typeface=\"Vrinda\"/>"
"<a:font script=\"Gujr\" typeface=\"Shruti\"/>"
"<a:font script=\"Khmr\" typeface=\"DaunPenh\"/>"
"<a:font script=\"Knda\" typeface=\"Tunga\"/>"
"<a:font script=\"Guru\" typeface=\"Raavi\"/>"
"<a:font script=\"Cans\" typeface=\"Euphemia\"/>"
"<a:font script=\"Cher\" typeface=\"Plantagenet Cherokee\"/>"
"<a:font script=\"Yiii\" typeface=\"Microsoft Yi Baiti\"/>"
"<a:font script=\"Tibt\" typeface=\"Microsoft Himalaya\"/>"
"<a:font script=\"Thaa\" typeface=\"MV Boli\"/>"
"<a:font script=\"Deva\" typeface=\"Mangal\"/>"
"<a:font script=\"Telu\" typeface=\"Gautami\"/>"
"<a:font script=\"Taml\" typeface=\"Latha\"/>"
"<a:font script=\"Syrc\" typeface=\"Estrangelo Edessa\"/>"
"<a:font script=\"Orya\" typeface=\"Kalinga\"/>"
"<a:font script=\"Mlym\" typeface=\"Kartika\"/>"
"<a:font script=\"Laoo\" typeface=\"DokChampa\"/>"
"<a:font script=\"Sinh\" typeface=\"Iskoola Pota\"/>"
"<a:font script=\"Mong\" typeface=\"Mongolian Baiti\"/>"
"<a:font script=\"Viet\" typeface=\"Arial\"/>"
"<a:font script=\"Uigh\" typeface=\"Microsoft Uighur\"/>"
"</a:minorFont>"
"</a:fontScheme>"
"<a:fmtScheme name=\"Office\">"
"<a:fillStyleLst>"
"<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: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: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:prstDash val=\"solid\"/>"
"</a:ln>"
"<a:ln w=\"25400\" cap=\"flat\" cmpd=\"sng\" algn=\"ctr\">"
"<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>"
"<a:prstDash val=\"solid\"/>"
"</a:ln>"
"<a:ln w=\"38100\" cap=\"flat\" cmpd=\"sng\" algn=\"ctr\">"
"<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>"
"<a:prstDash val=\"solid\"/>"
"</a:ln>"
"</a:lnStyleLst>"
"<a:effectStyleLst>"
"<a:effectStyle>"
"<a:effectLst>"
"<a:outerShdw blurRad=\"40000\" dist=\"20000\" dir=\"5400000\" rotWithShape=\"0\">"
"<a:srgbClr val=\"000000\"><a:alpha val=\"38000\"/></a:srgbClr>"
"</a:outerShdw>"
"</a:effectLst>"
"</a:effectStyle>"
"<a:effectStyle>"
"<a:effectLst>"
"<a:outerShdw blurRad=\"40000\" dist=\"23000\" dir=\"5400000\" rotWithShape=\"0\">"
"<a:srgbClr val=\"000000\"><a:alpha val=\"35000\"/></a:srgbClr>"
"</a:outerShdw>"
"</a:effectLst>"
"</a:effectStyle>"
"<a:effectStyle>"
"<a:effectLst>"
"<a:outerShdw blurRad=\"40000\" dist=\"23000\" dir=\"5400000\" rotWithShape=\"0\">"
"<a:srgbClr val=\"000000\"><a:alpha val=\"35000\"/></a:srgbClr>"
"</a:outerShdw>"
"</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:scene3d>"
"<a:sp3d><a:bevelT w=\"63500\" h=\"25400\"/></a:sp3d>"
"</a:effectStyle>"
"</a:effectStyleLst>"
"<a:bgFillStyleLst>"
"<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: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:gsLst>"
"<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>"
;
"<?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:themeElements>"
"<a:clrScheme name=\"Office\">"
"<a:dk1><a:sysClr val=\"windowText\" lastClr=\"000000\"/></a:dk1>"
"<a:lt1><a:sysClr val=\"window\" lastClr=\"FFFFFF\"/></a:lt1>"
"<a:dk2><a:srgbClr val=\"1F497D\"/></a:dk2>"
"<a:lt2><a:srgbClr val=\"EEECE1\"/></a:lt2>"
"<a:accent1><a:srgbClr val=\"4F81BD\"/></a:accent1>"
"<a:accent2><a:srgbClr val=\"C0504D\"/></a:accent2>"
"<a:accent3><a:srgbClr val=\"9BBB59\"/></a:accent3>"
"<a:accent4><a:srgbClr val=\"8064A2\"/></a:accent4>"
"<a:accent5><a:srgbClr val=\"4BACC6\"/></a:accent5>"
"<a:accent6><a:srgbClr val=\"F79646\"/></a:accent6>"
"<a:hlink><a:srgbClr val=\"0000FF\"/></a:hlink>"
"<a:folHlink><a:srgbClr val=\"800080\"/></a:folHlink>"
"</a:clrScheme>"
"<a:fontScheme name=\"Office\">"
"<a:majorFont>"
"<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=\"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\"/>"
"<a:font script=\"Arab\" typeface=\"Times New Roman\"/>"
"<a:font script=\"Hebr\" typeface=\"Times New Roman\"/>"
"<a:font script=\"Thai\" typeface=\"Tahoma\"/>"
"<a:font script=\"Ethi\" typeface=\"Nyala\"/>"
"<a:font script=\"Beng\" typeface=\"Vrinda\"/>"
"<a:font script=\"Gujr\" typeface=\"Shruti\"/>"
"<a:font script=\"Khmr\" typeface=\"MoolBoran\"/>"
"<a:font script=\"Knda\" typeface=\"Tunga\"/>"
"<a:font script=\"Guru\" typeface=\"Raavi\"/>"
"<a:font script=\"Cans\" typeface=\"Euphemia\"/>"
"<a:font script=\"Cher\" typeface=\"Plantagenet Cherokee\"/>"
"<a:font script=\"Yiii\" typeface=\"Microsoft Yi Baiti\"/>"
"<a:font script=\"Tibt\" typeface=\"Microsoft Himalaya\"/>"
"<a:font script=\"Thaa\" typeface=\"MV Boli\"/>"
"<a:font script=\"Deva\" typeface=\"Mangal\"/>"
"<a:font script=\"Telu\" typeface=\"Gautami\"/>"
"<a:font script=\"Taml\" typeface=\"Latha\"/>"
"<a:font script=\"Syrc\" typeface=\"Estrangelo Edessa\"/>"
"<a:font script=\"Orya\" typeface=\"Kalinga\"/>"
"<a:font script=\"Mlym\" typeface=\"Kartika\"/>"
"<a:font script=\"Laoo\" typeface=\"DokChampa\"/>"
"<a:font script=\"Sinh\" typeface=\"Iskoola Pota\"/>"
"<a:font script=\"Mong\" typeface=\"Mongolian Baiti\"/>"
"<a:font script=\"Viet\" typeface=\"Times New Roman\"/>"
"<a:font script=\"Uigh\" typeface=\"Microsoft Uighur\"/>"
"</a:majorFont>"
"<a:minorFont>"
"<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=\"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\"/>"
"<a:font script=\"Arab\" typeface=\"Arial\"/>"
"<a:font script=\"Hebr\" typeface=\"Arial\"/>"
"<a:font script=\"Thai\" typeface=\"Tahoma\"/>"
"<a:font script=\"Ethi\" typeface=\"Nyala\"/>"
"<a:font script=\"Beng\" typeface=\"Vrinda\"/>"
"<a:font script=\"Gujr\" typeface=\"Shruti\"/>"
"<a:font script=\"Khmr\" typeface=\"DaunPenh\"/>"
"<a:font script=\"Knda\" typeface=\"Tunga\"/>"
"<a:font script=\"Guru\" typeface=\"Raavi\"/>"
"<a:font script=\"Cans\" typeface=\"Euphemia\"/>"
"<a:font script=\"Cher\" typeface=\"Plantagenet Cherokee\"/>"
"<a:font script=\"Yiii\" typeface=\"Microsoft Yi Baiti\"/>"
"<a:font script=\"Tibt\" typeface=\"Microsoft Himalaya\"/>"
"<a:font script=\"Thaa\" typeface=\"MV Boli\"/>"
"<a:font script=\"Deva\" typeface=\"Mangal\"/>"
"<a:font script=\"Telu\" typeface=\"Gautami\"/>"
"<a:font script=\"Taml\" typeface=\"Latha\"/>"
"<a:font script=\"Syrc\" typeface=\"Estrangelo Edessa\"/>"
"<a:font script=\"Orya\" typeface=\"Kalinga\"/>"
"<a:font script=\"Mlym\" typeface=\"Kartika\"/>"
"<a:font script=\"Laoo\" typeface=\"DokChampa\"/>"
"<a:font script=\"Sinh\" typeface=\"Iskoola Pota\"/>"
"<a:font script=\"Mong\" typeface=\"Mongolian Baiti\"/>"
"<a:font script=\"Viet\" typeface=\"Arial\"/>"
"<a:font script=\"Uigh\" typeface=\"Microsoft Uighur\"/>"
"</a:minorFont>"
"</a:fontScheme>"
"<a:fmtScheme name=\"Office\">"
"<a:fillStyleLst>"
"<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: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: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:prstDash val=\"solid\"/>"
"</a:ln>"
"<a:ln w=\"25400\" cap=\"flat\" cmpd=\"sng\" algn=\"ctr\">"
"<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>"
"<a:prstDash val=\"solid\"/>"
"</a:ln>"
"<a:ln w=\"38100\" cap=\"flat\" cmpd=\"sng\" algn=\"ctr\">"
"<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>"
"<a:prstDash val=\"solid\"/>"
"</a:ln>"
"</a:lnStyleLst>"
"<a:effectStyleLst>"
"<a:effectStyle>"
"<a:effectLst>"
"<a:outerShdw blurRad=\"40000\" dist=\"20000\" dir=\"5400000\" rotWithShape=\"0\">"
"<a:srgbClr val=\"000000\"><a:alpha val=\"38000\"/></a:srgbClr>"
"</a:outerShdw>"
"</a:effectLst>"
"</a:effectStyle>"
"<a:effectStyle>"
"<a:effectLst>"
"<a:outerShdw blurRad=\"40000\" dist=\"23000\" dir=\"5400000\" rotWithShape=\"0\">"
"<a:srgbClr val=\"000000\"><a:alpha val=\"35000\"/></a:srgbClr>"
"</a:outerShdw>"
"</a:effectLst>"
"</a:effectStyle>"
"<a:effectStyle>"
"<a:effectLst>"
"<a:outerShdw blurRad=\"40000\" dist=\"23000\" dir=\"5400000\" rotWithShape=\"0\">"
"<a:srgbClr val=\"000000\"><a:alpha val=\"35000\"/></a:srgbClr>"
"</a:outerShdw>"
"</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:scene3d>"
"<a:sp3d><a:bevelT w=\"63500\" h=\"25400\"/></a:sp3d>"
"</a:effectStyle>"
"</a:effectStyleLst>"
"<a:bgFillStyleLst>"
"<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: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:gsLst>"
"<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>";
Theme::Theme(CreateFlag flag)
:AbstractOOXmlFile(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)
@ -30,9 +30,9 @@ QStringList splitPath(const QString &path)
{
int idx = path.lastIndexOf(QLatin1Char('/'));
if (idx == -1)
return { QStringLiteral("."), path };
return {QStringLiteral("."), path};
return { path.left(idx), path.mid(idx+1) };
return {path.left(idx), path.mid(idx + 1)};
}
/*
@ -52,22 +52,23 @@ 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;
}
double datetimeToNumber(const QDateTime &dt, bool is1904)
{
//Note, for number 0, Excel2007 shown as 1900-1-0, which should be 1899-12-31
QDateTime epoch(is1904 ? QDate(1904, 1, 1): QDate(1899, 12, 31), QTime(0,0));
// Note, for number 0, Excel2007 shown as 1900-1-0, which should be 1899-12-31
QDateTime epoch(is1904 ? QDate(1904, 1, 1) : QDate(1899, 12, 31), QTime(0, 0));
double excel_time = epoch.msecsTo(dt) / (1000*60*60*24.0);
double excel_time = epoch.msecsTo(dt) / (1000 * 60 * 60 * 24.0);
if (dt.isDaylightTime()) // Add one hour if the date is Daylight
if (dt.isDaylightTime()) // Add one hour if the date is Daylight
excel_time += 1.0 / 24.0;
if (!is1904 && excel_time > 59) {//31+28
//Account for Excel erroneously treating 1900 as a leap year.
if (!is1904 && excel_time > 59) { // 31+28
// Account for Excel erroneously treating 1900 as a leap year.
excel_time += 1;
}
@ -76,7 +77,7 @@ double datetimeToNumber(const QDateTime &dt, bool is1904)
double timeToNumber(const QTime &time)
{
return QTime(0,0).msecsTo(time) / (1000*60*60*24.0);
return QTime(0, 0).msecsTo(time) / (1000 * 60 * 60 * 24.0);
}
QVariant datetimeFromNumber(double num, bool is1904)
@ -88,30 +89,27 @@ QVariant datetimeFromNumber(double num, bool is1904)
num = num - 1;
}
qint64 msecs = static_cast<qint64>(num * 1000*60*60*24.0 + 0.5);
QDateTime epoch(is1904 ? QDate(1904, 1, 1): QDate(1899, 12, 31), QTime(0,0));
qint64 msecs = static_cast<qint64>(num * 1000 * 60 * 60 * 24.0 + 0.5);
QDateTime epoch(is1904 ? QDate(1904, 1, 1) : QDate(1899, 12, 31), QTime(0, 0));
QDateTime dtOld = epoch.addMSecs(msecs);
dtRet = dtOld;
dtRet = dtOld;
// Remove one hour to see whether the date is Daylight
QDateTime dtNew = dtRet.addMSecs( -3600000 ); // issue102
if ( dtNew.isDaylightTime() )
{
QDateTime dtNew = dtRet.addMSecs(-3600000); // issue102
if (dtNew.isDaylightTime()) {
dtRet = dtNew;
}
double whole = 0;
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,10 +133,11 @@ 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.
// Replace invalid chars with space.
static QRegularExpression invalidChars(QStringLiteral("[/\\\\?*\\][:]"));
if (nameProposal.contains(invalidChars)) {
static QRegularExpression validChars(QStringLiteral("[/\\\\?*\\][:]"));
@ -149,7 +148,7 @@ QString createSafeSheetName(const QString &nameProposal)
ret[0] = QLatin1Char(' ');
if (ret.endsWith(QLatin1Char('\'')))
ret[ret.size()-1] = QLatin1Char(' ');
ret[ret.size() - 1] = QLatin1Char(' ');
if (ret.size() > 31)
ret = ret.left(31);
@ -157,19 +156,20 @@ 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)
{
//Already escaped.
// Already escaped.
Q_ASSERT(!sheetName.startsWith(QLatin1Char('\'')) && !sheetName.endsWith(QLatin1Char('\'')));
//These is no need to escape
// These is no need to escape
static const auto escape = QRegularExpression(QStringLiteral("[ +\\-,%^=<>'&]"));
if (!sheetName.contains(escape))
return sheetName;
//OK, escape is needed.
// OK, escape is needed.
QString name = sheetName;
name.replace(QLatin1Char('\''), QLatin1String("\'\'"));
return QLatin1Char('\'') + name + QLatin1Char('\'');
@ -179,9 +179,10 @@ 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);
QString name = sheetName.mid(1, sheetName.length() - 2);
name.replace(QLatin1String("\'\'"), QLatin1String("\'"));
return name;
}
@ -192,7 +193,7 @@ QString unescapeSheetName(const QString &sheetName)
bool isSpaceReserveNeeded(const QString &s)
{
QString spaces(QStringLiteral(" \t\n\r"));
return !s.isEmpty() && (spaces.contains(s.at(0))||spaces.contains(s.at(s.length()-1)));
return !s.isEmpty() && (spaces.contains(s.at(0)) || spaces.contains(s.at(s.length() - 1)));
}
/*
@ -206,18 +207,20 @@ 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)
//Find all the "$?[A-Z]+$?[0-9]+" patterns in the rootFormula.
QVector<std::pair<QString, int> > segments;
// Find all the "$?[A-Z]+$?[0-9]+" patterns in the rootFormula.
QVector<std::pair<QString, int>> segments;
QString segment;
bool inQuote = false;
enum RefState{INVALID, PRE_AZ, AZ, PRE_09, _09};
enum RefState { INVALID, PRE_AZ, AZ, PRE_09, _09 };
RefState refState = INVALID;
int refFlag = 0; // 0x00, 0x01, 0x02, 0x03 ==> A1, $A1, A$1, $A$1
int refFlag = 0; // 0x00, 0x01, 0x02, 0x03 ==> A1, $A1, A$1, $A$1
for (QChar ch : rootFormula) {
if (inQuote) {
segment.append(ch);
@ -225,7 +228,7 @@ QString convertSharedFormula(const QString &rootFormula, const CellReference &ro
inQuote = false;
} else {
if (ch == QLatin1Char('"')) {
inQuote = true;
inQuote = true;
refState = INVALID;
segment.append(ch);
} else if (ch == QLatin1Char('$')) {
@ -234,21 +237,21 @@ QString convertSharedFormula(const QString &rootFormula, const CellReference &ro
refState = PRE_09;
refFlag |= 0x02;
} else {
segments.append(std::make_pair(segment, refState==_09 ? refFlag : -1 ));
segment = QString(ch); //Start new segment.
segments.append(std::make_pair(segment, refState == _09 ? refFlag : -1));
segment = QString(ch); // Start new segment.
refState = PRE_AZ;
refFlag = 0x01;
refFlag = 0x01;
}
} else if (ch >= QLatin1Char('A') && ch <=QLatin1Char('Z')) {
} else if (ch >= QLatin1Char('A') && ch <= QLatin1Char('Z')) {
if (refState == PRE_AZ || refState == AZ) {
segment.append(ch);
} else {
segments.append(std::make_pair(segment, refState==_09 ? refFlag : -1 ));
segment = QString(ch); //Start new segment.
segments.append(std::make_pair(segment, refState == _09 ? refFlag : -1));
segment = QString(ch); // Start new segment.
refFlag = 0x00;
}
refState = AZ;
} else if (ch >= QLatin1Char('0') && ch <=QLatin1Char('9')) {
} else if (ch >= QLatin1Char('0') && ch <= QLatin1Char('9')) {
segment.append(ch);
if (refState == AZ || refState == PRE_09 || refState == _09)
@ -257,8 +260,8 @@ QString convertSharedFormula(const QString &rootFormula, const CellReference &ro
refState = INVALID;
} else {
if (refState == _09) {
segments.append(std::make_pair(segment, refFlag ));
segment = QString(ch); //Start new segment.
segments.append(std::make_pair(segment, refFlag));
segment = QString(ch); // Start new segment.
} else {
segment.append(ch);
}
@ -268,23 +271,24 @@ QString convertSharedFormula(const QString &rootFormula, const CellReference &ro
}
if (!segment.isEmpty())
segments.append(std::make_pair(segment, refState==_09 ? refFlag : -1 ));
segments.append(std::make_pair(segment, refState == _09 ? refFlag : -1));
//Replace "A1", "$A1", "A$1" segment with proper one.
// Replace "A1", "$A1", "A$1" segment with proper one.
QStringList result;
for (const auto &p : segments) {
//qDebug()<<p.first<<p.second;
// qDebug()<<p.first<<p.second;
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 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();
result.append(CellReference(row, col).toString(p.second & 0x02, p.second & 0x01));
} else {
result.append(p.first);
}
}
//OK
// OK
return result.join(QString());
}

View File

@ -1,63 +1,61 @@
// 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));
theme = QSharedPointer<Theme>(new Theme(flag));
sharedStrings = QSharedPointer<SharedStrings>(new SharedStrings(flag));
styles = QSharedPointer<Styles>(new Styles(flag));
theme = QSharedPointer<Theme>(new Theme(flag));
x_window = 240;
y_window = 15;
window_width = 16095;
x_window = 240;
y_window = 15;
window_width = 16095;
window_height = 9660;
strings_to_numbers_enabled = false;
strings_to_numbers_enabled = false;
strings_to_hyperlinks_enabled = true;
html_to_richstring_enabled = false;
date1904 = false;
defaultDateFormat = QStringLiteral("yyyy-mm-dd");
activesheetIndex = 0;
firstsheet = 0;
table_count = 0;
html_to_richstring_enabled = false;
date1904 = false;
defaultDateFormat = QStringLiteral("yyyy-mm-dd");
activesheetIndex = 0;
firstsheet = 0;
table_count = 0;
last_worksheet_index = 0;
last_worksheet_index = 0;
last_chartsheet_index = 0;
last_sheet_id = 0;
last_sheet_id = 0;
}
Workbook::Workbook(CreateFlag flag)
: AbstractOOXmlFile(new WorkbookPrivate(this, flag))
{
}
Workbook::~Workbook()
{
}
Workbook::~Workbook() {}
bool Workbook::isDate1904() const
{
@ -144,18 +142,21 @@ 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);
//Remove the = sign from the formula if it exists.
// Remove the = sign from the formula if it exists.
QString formulaString = formula;
if (formulaString.startsWith(QLatin1Char('=')))
formulaString = formula.mid(1);
int id=-1;
int id = -1;
if (!scope.isEmpty()) {
for (int i=0; i<d->sheets.size(); ++i) {
for (int i = 0; i < d->sheets.size(); ++i) {
if (d->sheets[i]->sheetName() == scope) {
id = d->sheets[i]->sheetId();
break;
@ -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);
}
@ -219,12 +215,12 @@ AbstractSheet *Workbook::insertSheet(int index, const QString &name, AbstractShe
{
Q_D(Workbook);
QString sheetName = createSafeSheetName(name);
if(index > d->last_sheet_id){
//User tries to insert, where no sheet has gone before.
if (index > d->last_sheet_id) {
// User tries to insert, where no sheet has gone before.
return 0;
}
if (!sheetName.isEmpty()) {
//If user given an already in-used name, we should not continue any more!
// If user given an already in-used name, we should not continue any more!
if (d->sheetNames.contains(sheetName))
return 0;
} else {
@ -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);
}
@ -275,7 +266,7 @@ AbstractSheet *Workbook::activeSheet() const
{
Q_D(const Workbook);
if (d->sheets.isEmpty())
const_cast<Workbook*>(this)->addSheet();
const_cast<Workbook *>(this)->addSheet();
return d->sheets[d->activesheetIndex].data();
}
@ -283,7 +274,7 @@ bool Workbook::setActiveSheet(int index)
{
Q_D(Workbook);
if (index < 0 || index >= d->sheets.size()) {
//warning
// warning
return false;
}
d->activesheetIndex = index;
@ -300,8 +291,8 @@ bool Workbook::renameSheet(int index, const QString &newName)
if (index < 0 || index >= d->sheets.size())
return false;
//If user given an already in-used name, return false
for (int i=0; i<d->sheets.size(); ++i) {
// If user given an already in-used name, return false
for (int i = 0; i < d->sheets.size(); ++i) {
if (d->sheets[i]->sheetName() == name)
return false;
}
@ -358,20 +349,21 @@ bool Workbook::copySheet(int index, const QString &newName)
QString worksheetName = createSafeSheetName(newName);
if (!newName.isEmpty()) {
//If user given an already in-used name, we should not continue any more!
// If user given an already in-used name, we should not continue any more!
if (d->sheetNames.contains(newName))
return false;
} else {
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));
}
++d->last_sheet_id;
AbstractSheet *sheet = d->sheets[index]->copy(worksheetName, d->last_sheet_id);
d->sheets.append(QSharedPointer<AbstractSheet> (sheet));
d->sheets.append(QSharedPointer<AbstractSheet>(sheet));
d->sheetNames.append(sheet->sheetName());
return true; // #162
@ -424,10 +416,10 @@ QList<Drawing *> Workbook::drawings()
{
Q_D(Workbook);
QList<Drawing *> ds;
for (int i=0; i<d->sheets.size(); ++i) {
for (int i = 0; i < d->sheets.size(); ++i) {
QSharedPointer<AbstractSheet> sheet = d->sheets[i];
if (sheet->drawing())
ds.append(sheet->drawing());
ds.append(sheet->drawing());
}
return ds;
@ -436,11 +428,11 @@ QList<Drawing *> Workbook::drawings()
/*!
* \internal
*/
QList<QSharedPointer<AbstractSheet> > Workbook::getSheetsByTypes(AbstractSheet::SheetType type) const
QList<QSharedPointer<AbstractSheet>> Workbook::getSheetsByTypes(AbstractSheet::SheetType type) const
{
Q_D(const Workbook);
QList<QSharedPointer<AbstractSheet> > list;
for (int i=0; i<d->sheets.size(); ++i) {
QList<QSharedPointer<AbstractSheet>> list;
for (int i = 0; i < d->sheets.size(); ++i) {
if (d->sheets[i]->sheetType() == type)
list.append(d->sheets[i]);
}
@ -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)
@ -479,19 +476,19 @@ void Workbook::saveToXmlFile(QIODevice *device) const
writer.writeAttribute(QStringLiteral("yWindow"), QString::number(d->y_window));
writer.writeAttribute(QStringLiteral("windowWidth"), QString::number(d->window_width));
writer.writeAttribute(QStringLiteral("windowHeight"), QString::number(d->window_height));
//Store the firstSheet when it isn't the default
//For example, when "the first sheet 0 is hidden", the first sheet will be 1
// Store the firstSheet when it isn't the default
// For example, when "the first sheet 0 is hidden", the first sheet will be 1
if (d->firstsheet > 0)
writer.writeAttribute(QStringLiteral("firstSheet"), QString::number(d->firstsheet + 1));
//Store the activeTab when it isn't the first sheet
// Store the activeTab when it isn't the first sheet
if (d->activesheetIndex > 0)
writer.writeAttribute(QStringLiteral("activeTab"), QString::number(d->activesheetIndex));
writer.writeEndElement();//bookViews
writer.writeEndElement(); // bookViews
writer.writeStartElement(QStringLiteral("sheets"));
int worksheetIndex = 0;
int worksheetIndex = 0;
int chartsheetIndex = 0;
for (int i=0; i<d->sheets.size(); ++i) {
for (int i = 0; i < d->sheets.size(); ++i) {
QSharedPointer<AbstractSheet> sheet = d->sheets[i];
writer.writeEmptyElement(QStringLiteral("sheet"));
writer.writeAttribute(QStringLiteral("name"), sheet->sheetName());
@ -502,22 +499,30 @@ 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
writer.writeEndElement(); // sheets
if (d->externalLinks.size() > 0) {
writer.writeStartElement(QStringLiteral("externalReferences"));
for (int i=0; i<d->externalLinks.size(); ++i) {
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
writer.writeEndElement(); // externalReferences
}
if (!d->definedNamesList.isEmpty()) {
@ -528,8 +533,8 @@ void Workbook::saveToXmlFile(QIODevice *device) const
if (!data.comment.isEmpty())
writer.writeAttribute(QStringLiteral("comment"), data.comment);
if (data.sheetId != -1) {
//find the local index of the sheet.
for (int i=0; i<d->sheets.size(); ++i) {
// find the local index of the sheet.
for (int i = 0; i < d->sheets.size(); ++i) {
if (d->sheets[i]->sheetId() == data.sheetId) {
writer.writeAttribute(QStringLiteral("localSheetId"), QString::number(i));
break;
@ -537,22 +542,25 @@ void Workbook::saveToXmlFile(QIODevice *device) const
}
}
writer.writeCharacters(data.formula);
writer.writeEndElement();//definedName
writer.writeEndElement(); // definedName
}
writer.writeEndElement();//definedNames
writer.writeEndElement(); // definedNames
}
writer.writeStartElement(QStringLiteral("calcPr"));
writer.writeAttribute(QStringLiteral("calcId"), QStringLiteral("124519"));
writer.writeEndElement(); //calcPr
writer.writeEndElement(); // calcPr
writer.writeEndElement();//workbook
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,79 +568,62 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
Q_D(Workbook);
QXmlStreamReader reader(device);
while (!reader.atEnd())
{
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement)
{
if (reader.name() == QLatin1String("sheet"))
{
QXmlStreamAttributes attributes = reader.attributes();
while (!reader.atEnd()) {
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("sheet")) {
QXmlStreamAttributes attributes = reader.attributes();
const auto& name = attributes.value(QLatin1String("name")).toString();
const auto &name = attributes.value(QLatin1String("name")).toString();
int sheetId = attributes.value(QLatin1String("sheetId")).toInt();
int sheetId = attributes.value(QLatin1String("sheetId")).toInt();
const auto& rId = attributes.value(QLatin1String("r:id")).toString();
const auto &rId = attributes.value(QLatin1String("r:id")).toString();
const auto& stateString = attributes.value(QLatin1String("state"));
const auto &stateString = attributes.value(QLatin1String("state"));
AbstractSheet::SheetState state = AbstractSheet::SS_Visible;
if (stateString == QLatin1String("hidden"))
state = AbstractSheet::SS_Hidden;
else if (stateString == QLatin1String("veryHidden"))
state = AbstractSheet::SS_VeryHidden;
AbstractSheet::SheetState state = AbstractSheet::SS_Visible;
if (stateString == QLatin1String("hidden"))
state = AbstractSheet::SS_Hidden;
else if (stateString == QLatin1String("veryHidden"))
state = AbstractSheet::SS_VeryHidden;
XlsxRelationship relationship = d->relationships->getRelationshipById(rId);
XlsxRelationship relationship = d->relationships->getRelationshipById(rId);
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet;
if (relationship.type.endsWith(QLatin1String("/worksheet")))
{
type = AbstractSheet::ST_WorkSheet;
}
else if (relationship.type.endsWith(QLatin1String("/chartsheet")))
{
type = AbstractSheet::ST_ChartSheet;
}
else if (relationship.type.endsWith(QLatin1String("/dialogsheet")))
{
type = AbstractSheet::ST_DialogSheet;
}
else if (relationship.type.endsWith(QLatin1String("/xlMacrosheet")))
{
type = AbstractSheet::ST_MacroSheet;
}
else
{
qWarning() << "unknown sheet type : " << relationship.type ;
}
AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet;
if (relationship.type.endsWith(QLatin1String("/worksheet"))) {
type = AbstractSheet::ST_WorkSheet;
} else if (relationship.type.endsWith(QLatin1String("/chartsheet"))) {
type = AbstractSheet::ST_ChartSheet;
} else if (relationship.type.endsWith(QLatin1String("/dialogsheet"))) {
type = AbstractSheet::ST_DialogSheet;
} else if (relationship.type.endsWith(QLatin1String("/xlMacrosheet"))) {
type = AbstractSheet::ST_MacroSheet;
} else {
qWarning() << "unknown sheet type : " << relationship.type;
}
AbstractSheet *sheet = addSheet(name, sheetId, type);
sheet->setSheetState(state);
QString strFilePath = filePath();
AbstractSheet *sheet = addSheet(name, sheetId, type);
sheet->setSheetState(state);
QString strFilePath = filePath();
// 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);
// 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);
sheet->setFilePath(fullPath);
}
else if (reader.name() == QLatin1String("workbookPr"))
{
sheet->setFilePath(fullPath);
} 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,44 +632,45 @@ 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"))
{
QXmlStreamAttributes attributes = reader.attributes();
const QString rId = attributes.value(QLatin1String("r:id")).toString();
XlsxRelationship relationship = d->relationships->getRelationshipById(rId);
} 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);
QSharedPointer<SimpleOOXmlFile> link(new SimpleOOXmlFile(F_LoadFromExists));
QSharedPointer<SimpleOOXmlFile> link(new SimpleOOXmlFile(F_LoadFromExists));
const auto parts = splitPath(filePath());
QString fullPath = QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
const auto parts = splitPath(filePath());
QString fullPath =
QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
link->setFilePath(fullPath);
d->externalLinks.append(link);
} else if (reader.name() == QLatin1String("definedName")) {
QXmlStreamAttributes attrs = reader.attributes();
XlsxDefineNameData data;
link->setFilePath(fullPath);
d->externalLinks.append(link);
} else if (reader.name() == QLatin1String("definedName")) {
QXmlStreamAttributes attrs = reader.attributes();
XlsxDefineNameData data;
data.name = attrs.value(QLatin1String("name")).toString();
if (attrs.hasAttribute(QLatin1String("comment")))
data.comment = attrs.value(QLatin1String("comment")).toString();
if (attrs.hasAttribute(QLatin1String("localSheetId"))) {
int localId = attrs.value(QLatin1String("localSheetId")).toInt();
int sheetId = d->sheets.at(localId)->sheetId();
data.sheetId = sheetId;
}
data.formula = reader.readElementText();
d->definedNamesList.append(data);
}
}
data.name = attrs.value(QLatin1String("name")).toString();
if (attrs.hasAttribute(QLatin1String("comment")))
data.comment = attrs.value(QLatin1String("comment")).toString();
if (attrs.hasAttribute(QLatin1String("localSheetId"))) {
int localId = attrs.value(QLatin1String("localSheetId")).toInt();
int sheetId = d->sheets.at(localId)->sheetId();
data.sheetId = sheetId;
}
data.formula = reader.readElementText();
d->definedNamesList.append(data);
}
}
}
return true;
}
@ -686,7 +678,7 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
/*!
* \internal
*/
QList<std::shared_ptr<MediaFile> > Workbook::mediaFiles() const
QList<std::shared_ptr<MediaFile>> Workbook::mediaFiles() const
{
Q_D(const Workbook);
@ -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;
}
@ -719,7 +708,7 @@ void Workbook::addMediaFile(std::shared_ptr<MediaFile> media, bool force)
/*!
* \internal
*/
QList<QSharedPointer<Chart> > Workbook::chartFiles() const
QList<QSharedPointer<Chart>> Workbook::chartFiles() const
{
Q_D(const Workbook);

File diff suppressed because it is too large Load Diff

View File

@ -6,26 +6,23 @@
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()
{
const auto& allFiles = m_reader->fileInfoList();
const auto &allFiles = m_reader->fileInfoList();
for (const auto &fi : allFiles) {
if (fi.isFile || (!fi.isDir && !fi.isFile && !fi.isSymLink))
m_filePaths.append(fi.filePath);

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,67 +1,63 @@
// 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;
void printColor(Cell* cell);
void saveColor(Cell* cell);
void printColor(Cell *cell);
void saveColor(Cell *cell);
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Document xlsxR(":/color.xlsx");
if ( !xlsxR.load() )
{
if (!xlsxR.load()) {
return (-1);
}
printColor( xlsxR.cellAt(1, 1) );
printColor( xlsxR.cellAt(1, 2) );
printColor( xlsxR.cellAt(2, 1) );
printColor( xlsxR.cellAt(2, 2) );
printColor(xlsxR.cellAt(1, 1));
printColor(xlsxR.cellAt(1, 2));
printColor(xlsxR.cellAt(2, 1));
printColor(xlsxR.cellAt(2, 2));
xlsxR.write( 3, 3, QVariant("HELLO") );
saveColor( xlsxR.cellAt(3, 3) );
xlsxR.write(3, 3, QVariant("HELLO"));
saveColor(xlsxR.cellAt(3, 3));
xlsxR.saveAs("color2.xlsx");
return 0;
}
void printColor(Cell* cell)
void printColor(Cell *cell)
{
if ( NULL == cell )
if (NULL == cell)
return;
QColor clrForeGround = cell->format().patternForegroundColor();
QColor clrBackGround = cell->format().patternBackgroundColor();
if ( clrForeGround.isValid() &&
clrBackGround.isValid() )
{
qDebug() << "[debug] color : " << clrForeGround << clrBackGround;
}
QColor clrForeGround = cell->format().patternForegroundColor();
QColor clrBackGround = cell->format().patternBackgroundColor();
if (clrForeGround.isValid() && clrBackGround.isValid()) {
qDebug() << "[debug] color : " << clrForeGround << clrBackGround;
}
}
void saveColor(Cell* cell)
void saveColor(Cell *cell)
{
cell->format().setVerticalAlignment(QXlsx::Format::AlignVCenter);
@ -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
*****************************************************************************/
@ -60,24 +59,20 @@ SOFTWARE.
/** #define FT_CONGIG_HAVE_WCHAR */
#if defined(FT_CONGIG_HAVE_WCHAR)
#define FT_HAVE_WCHAR
# define FT_HAVE_WCHAR
#endif
/*****************************************************************************
* RETURN CODES
*****************************************************************************/
typedef int fort_status_t;
#define FT_SUCCESS 0
#define FT_MEMORY_ERROR -1
#define FT_ERROR -2
#define FT_EINVAL -3
#define FT_SUCCESS 0
#define FT_MEMORY_ERROR -1
#define FT_ERROR -2
#define FT_EINVAL -3
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
#define FT_IS_ERROR(arg) ((arg) < 0)
/**
* @cond HELPER_MACROS
*/
@ -87,55 +82,50 @@ typedef int fort_status_t;
*****************************************************************************/
#if defined(__clang__)
#define FT_CLANG_COMPILER
# define FT_CLANG_COMPILER
#elif defined(__GNUC__)
#define FT_GCC_COMPILER
# define FT_GCC_COMPILER
#elif defined(_MSC_VER)
#define FT_MICROSOFT_COMPILER
# define FT_MICROSOFT_COMPILER
#else
#define FT_UNDEFINED_COMPILER
# define FT_UNDEFINED_COMPILER
#endif
/*****************************************************************************
* Declare inline
*****************************************************************************/
#if defined(__cplusplus)
#define FT_INLINE inline
# define FT_INLINE inline
#else
#define FT_INLINE __inline
# define FT_INLINE __inline
#endif /* if defined(__cplusplus) */
/*****************************************************************************
* C++ needs to know that types and declarations are C, not C++.
*****************************************************************************/
#ifdef __cplusplus
# define FT_BEGIN_DECLS extern "C" {
# define FT_END_DECLS }
# define FT_BEGIN_DECLS extern "C" {
# define FT_END_DECLS }
#else
# define FT_BEGIN_DECLS
# define FT_END_DECLS
# define FT_BEGIN_DECLS
# 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
*/
static FT_INLINE int ft_check_if_string_helper(const char *str)
{
(void)str;
(void) str;
return 0;
}
@ -144,77 +134,107 @@ static FT_INLINE int ft_check_if_string_helper(const char *str)
*/
static FT_INLINE int ft_check_if_wstring_helper(const wchar_t *str)
{
(void)str;
(void) str;
return 0;
}
#define FT_NARGS_IMPL_(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,N,...) N
#define FT_NARGS_IMPL_(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, N, ...) N
#define FT_EXPAND_(x) x
#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))
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_1(checker,arg) (checker(arg))
#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,basis, n, ...) \
FT_CHECK_IF_ARGS_ARE_STRINGS__(checker,FT_STR_2_CAT_(basis, n), __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__)
# 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__)
#endif
/**
* @endcond
*/
/*****************************************************************************
* Attribute format for argument checking
*****************************************************************************/
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
#define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check) \
__attribute__ ((format (printf, string_index, first_to_check)))
# define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check) \
__attribute__((format(printf, string_index, first_to_check)))
#else
#define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check)
# 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)
/**
@ -375,10 +393,10 @@ int ft_printf_ln(ft_table_t *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FO
int ft_printf_impl(ft_table_t *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
int ft_printf_ln_impl(ft_table_t *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
#define ft_printf(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_impl(table, __VA_ARGS__))
#define ft_printf_ln(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_ln_impl(table, __VA_ARGS__))
# define ft_printf(table, ...) \
((0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_impl(table, __VA_ARGS__))
# define ft_printf_ln(table, ...) \
((0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_ln_impl(table, __VA_ARGS__))
/**
* @endcond
@ -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.
*
@ -409,8 +426,9 @@ void ft_set_default_printf_field_separator(char separator);
* - 0: Success; data were written
* - (<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__))
#define ft_write(table, ...) \
(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.
@ -427,8 +445,9 @@ void ft_set_default_printf_field_separator(char separator);
* - 0: Success; data were written
* - (<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__))
#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__))
/**
* 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,61 +678,56 @@ 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).
* @{
*/
#define FT_ANY_COLUMN (UINT_MAX) /**< Any column (can be used to refer to all cells in a row)*/
#define FT_CUR_COLUMN (UINT_MAX - 1) /**< Current column */
#define FT_ANY_ROW (UINT_MAX) /**< Any row (can be used to refer to all cells in a column)*/
#define FT_CUR_ROW (UINT_MAX - 1) /**< Current row */
#define FT_ANY_ROW (UINT_MAX) /**< Any row (can be used to refer to all cells in a column)*/
#define FT_CUR_ROW (UINT_MAX - 1) /**< Current row */
/** @} */
/**
* @name Cell properties identifiers.
* @{
*/
#define FT_CPROP_MIN_WIDTH (0x01U << 0) /**< Minimum width */
#define FT_CPROP_TEXT_ALIGN (0x01U << 1) /**< Text alignment */
#define FT_CPROP_TOP_PADDING (0x01U << 2) /**< Top padding for cell content */
#define FT_CPROP_BOTTOM_PADDING (0x01U << 3) /**< Bottom padding for cell content */
#define FT_CPROP_LEFT_PADDING (0x01U << 4) /**< Left padding for cell content */
#define FT_CPROP_RIGHT_PADDING (0x01U << 5) /**< Right padding for cell content */
#define FT_CPROP_MIN_WIDTH (0x01U << 0) /**< Minimum width */
#define FT_CPROP_TEXT_ALIGN (0x01U << 1) /**< Text alignment */
#define FT_CPROP_TOP_PADDING (0x01U << 2) /**< Top padding for cell content */
#define FT_CPROP_BOTTOM_PADDING (0x01U << 3) /**< Bottom padding for cell content */
#define FT_CPROP_LEFT_PADDING (0x01U << 4) /**< Left padding for cell content */
#define FT_CPROP_RIGHT_PADDING (0x01U << 5) /**< Right padding for cell content */
#define FT_CPROP_EMPTY_STR_HEIGHT (0x01U << 6) /**< Height of empty cell */
#define FT_CPROP_ROW_TYPE (0x01U << 7) /**< Row type */
#define FT_CPROP_CONT_FG_COLOR (0x01U << 8) /**< Cell content foreground text color */
#define FT_CPROP_CELL_BG_COLOR (0x01U << 9) /**< Cell background color */
#define FT_CPROP_CONT_BG_COLOR (0x01U << 10) /**< Cell content background color */
#define FT_CPROP_CELL_TEXT_STYLE (0x01U << 11) /**< Cell text style */
#define FT_CPROP_CONT_TEXT_STYLE (0x01U << 12) /**< Cell content text style */
#define FT_CPROP_ROW_TYPE (0x01U << 7) /**< Row type */
#define FT_CPROP_CONT_FG_COLOR (0x01U << 8) /**< Cell content foreground text color */
#define FT_CPROP_CELL_BG_COLOR (0x01U << 9) /**< Cell background color */
#define FT_CPROP_CONT_BG_COLOR (0x01U << 10) /**< Cell content background color */
#define FT_CPROP_CELL_TEXT_STYLE (0x01U << 11) /**< Cell text style */
#define FT_CPROP_CONT_TEXT_STYLE (0x01U << 12) /**< Cell content text style */
/** @} */
/**
* Colors.
*/
enum ft_color {
FT_COLOR_DEFAULT = 0, /**< Default color */
FT_COLOR_BLACK = 1, /**< Black color*/
FT_COLOR_RED = 2, /**< Red color */
FT_COLOR_GREEN = 3, /**< Green color */
FT_COLOR_YELLOW = 4, /**< Yellow color */
FT_COLOR_BLUE = 5, /**< Blue color */
FT_COLOR_MAGENTA = 6, /**< Magenta color */
FT_COLOR_CYAN = 7, /**< Cyan color */
FT_COLOR_LIGHT_GRAY = 8, /**< Light gray color */
FT_COLOR_DARK_GRAY = 9, /**< Dark gray color */
FT_COLOR_LIGHT_RED = 10, /**< Light red color */
FT_COLOR_LIGHT_GREEN = 11, /**< Light green color */
FT_COLOR_LIGHT_YELLOW = 12, /**< Light yellow color */
FT_COLOR_LIGHT_BLUE = 13, /**< Light blue color */
FT_COLOR_LIGHT_MAGENTA = 15, /**< Light magenta color */
FT_COLOR_LIGHT_CYAN = 16, /**< Light cyan color */
FT_COLOR_LIGHT_WHYTE = 17 /**< Light whyte color */
FT_COLOR_DEFAULT = 0, /**< Default color */
FT_COLOR_BLACK = 1, /**< Black color*/
FT_COLOR_RED = 2, /**< Red color */
FT_COLOR_GREEN = 3, /**< Green color */
FT_COLOR_YELLOW = 4, /**< Yellow color */
FT_COLOR_BLUE = 5, /**< Blue color */
FT_COLOR_MAGENTA = 6, /**< Magenta color */
FT_COLOR_CYAN = 7, /**< Cyan color */
FT_COLOR_LIGHT_GRAY = 8, /**< Light gray color */
FT_COLOR_DARK_GRAY = 9, /**< Dark gray color */
FT_COLOR_LIGHT_RED = 10, /**< Light red color */
FT_COLOR_LIGHT_GREEN = 11, /**< Light green color */
FT_COLOR_LIGHT_YELLOW = 12, /**< Light yellow color */
FT_COLOR_LIGHT_BLUE = 13, /**< Light blue color */
FT_COLOR_LIGHT_MAGENTA = 15, /**< Light magenta color */
FT_COLOR_LIGHT_CYAN = 16, /**< Light cyan color */
FT_COLOR_LIGHT_WHYTE = 17 /**< Light whyte color */
};
/**
@ -745,22 +744,21 @@ enum ft_text_style {
FT_TSTYLE_HIDDEN = (1U << 7) /**< Hidden (useful for passwords) */
};
/**
* Alignment of cell content.
*/
enum ft_text_alignment {
FT_ALIGNED_LEFT = 0, /**< Align left */
FT_ALIGNED_CENTER, /**< Align center */
FT_ALIGNED_RIGHT /**< Align right */
FT_ALIGNED_LEFT = 0, /**< Align left */
FT_ALIGNED_CENTER, /**< Align center */
FT_ALIGNED_RIGHT /**< Align right */
};
/**
* Type of table row. Determines appearance of row.
*/
enum ft_row_type {
FT_ROW_COMMON = 0, /**< Common row */
FT_ROW_HEADER /**< Header row */
FT_ROW_COMMON = 0, /**< Common row */
FT_ROW_HEADER /**< Header row */
};
/**
@ -795,19 +793,16 @@ 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.
* @{
*/
#define FT_TPROP_LEFT_MARGIN (0x01U << 0)
#define FT_TPROP_TOP_MARGIN (0x01U << 1)
#define FT_TPROP_RIGHT_MARGIN (0x01U << 2)
#define FT_TPROP_LEFT_MARGIN (0x01U << 0)
#define FT_TPROP_TOP_MARGIN (0x01U << 1)
#define FT_TPROP_RIGHT_MARGIN (0x01U << 2)
#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__))
#define ft_wwrite_ln(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
# define ft_wwrite(table, ...) \
(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__))
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;
}
@ -39,54 +36,47 @@ int main(int argc, char *argv[])
qDebug() << xlsxFileName;
// tried to load xlsx using temporary document
QXlsx::Document xlsxTmp( xlsxFileName );
if ( !xlsxTmp.isLoadPackage() )
{
QXlsx::Document xlsxTmp(xlsxFileName);
if (!xlsxTmp.isLoadPackage()) {
qCritical() << "Failed to load" << xlsxFileName;
return (-1); // failed to load
}
// load new xlsx using new document
QXlsx::Document xlsxDoc( xlsxFileName );
QXlsx::Document xlsxDoc(xlsxFileName);
xlsxDoc.isLoadPackage();
int sheetIndexNumber = 0;
foreach( QString curretnSheetName, xlsxDoc.sheetNames() )
{
QXlsx::AbstractSheet* currentSheet = xlsxDoc.sheet( curretnSheetName );
if ( NULL == currentSheet )
foreach (QString curretnSheetName, xlsxDoc.sheetNames()) {
QXlsx::AbstractSheet *currentSheet = xlsxDoc.sheet(curretnSheetName);
if (NULL == currentSheet)
continue;
// get full cells of sheet
int maxRow = -1;
int maxCol = -1;
currentSheet->workbook()->setActiveSheet( sheetIndexNumber );
Worksheet* wsheet = (Worksheet*) currentSheet->workbook()->activeSheet();
if ( NULL == wsheet )
currentSheet->workbook()->setActiveSheet(sheetIndexNumber);
Worksheet *wsheet = (Worksheet *) currentSheet->workbook()->activeSheet();
if (NULL == wsheet)
continue;
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<CellLocation> clList = wsheet->getFullCells(&maxRow, &maxCol);
QVector< QVector<QString> > cellValues;
for (int rc = 0; rc < maxRow; rc++)
{
QVector<QVector<QString>> cellValues;
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,12 +99,10 @@ 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
fortTable << std::string(strTemp.toLocal8Bit()); // display value
}
fortTable << fort::endr; // change to new row
}
@ -124,6 +112,5 @@ int main(int argc, char *argv[])
sheetIndexNumber++;
}
return 0;
}

View File

@ -1,25 +1,24 @@
// 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);
//the header row
// the header row
Format headerStyle;
headerStyle.setFontSize(48);
headerStyle.setFontColor(Qt::darkBlue);
@ -29,8 +28,8 @@ int calendar()
xlsx.write("A1", QString("%1 %2").arg(QLocale().monthName(month)).arg(today.year()));
xlsx.mergeCells("A1:N1", headerStyle);
//header with month titles
for (int day=1; day<=7; ++day) {
// header with month titles
for (int day = 1; day <= 7; ++day) {
Format monthStyle;
monthStyle.setFontSize(12);
monthStyle.setFontColor(Qt::white);
@ -40,10 +39,10 @@ int calendar()
monthStyle.setFillPattern(Format::PatternSolid);
monthStyle.setPatternBackgroundColor(Qt::darkBlue);
xlsx.setColumnWidth(day*2-1, day*2-1, 5);
xlsx.setColumnWidth(day*2, day*2, 13);
xlsx.write(2, day*2-1, QLocale().dayName(day));
xlsx.mergeCells(CellRange(2, day*2-1, 2, day*2), monthStyle);
xlsx.setColumnWidth(day * 2 - 1, day * 2 - 1, 5);
xlsx.setColumnWidth(day * 2, day * 2, 13);
xlsx.write(2, day * 2 - 1, QLocale().dayName(day));
xlsx.mergeCells(CellRange(2, day * 2 - 1, 2, day * 2), monthStyle);
}
QColor borderColor = QColor(Qt::gray);
@ -68,25 +67,25 @@ int calendar()
weekendRightStyle.setBottomBorderStyle(Format::BorderThin);
weekendRightStyle.setBottomBorderColor(borderColor);
Format holidayLeftStyle;
holidayLeftStyle.setFontSize(14);
holidayLeftStyle.setFontBold(true);
holidayLeftStyle.setHorizontalAlignment(Format::AlignLeft);
holidayLeftStyle.setVerticalAlignment(Format::AlignTop);
holidayLeftStyle.setPatternBackgroundColor(QColor("#EACC93"));
holidayLeftStyle.setLeftBorderStyle(Format::BorderThin);
holidayLeftStyle.setLeftBorderColor(borderColor);
holidayLeftStyle.setBottomBorderStyle(Format::BorderThin);
holidayLeftStyle.setBottomBorderColor(borderColor);
Format holidayLeftStyle;
holidayLeftStyle.setFontSize(14);
holidayLeftStyle.setFontBold(true);
holidayLeftStyle.setHorizontalAlignment(Format::AlignLeft);
holidayLeftStyle.setVerticalAlignment(Format::AlignTop);
holidayLeftStyle.setPatternBackgroundColor(QColor("#EACC93"));
holidayLeftStyle.setLeftBorderStyle(Format::BorderThin);
holidayLeftStyle.setLeftBorderColor(borderColor);
holidayLeftStyle.setBottomBorderStyle(Format::BorderThin);
holidayLeftStyle.setBottomBorderColor(borderColor);
Format holidayRightStyle;
holidayRightStyle.setHorizontalAlignment(Format::AlignHCenter);
holidayRightStyle.setVerticalAlignment(Format::AlignTop);
holidayRightStyle.setPatternBackgroundColor(QColor("#EACC93"));
holidayRightStyle.setRightBorderStyle(Format::BorderThin);
holidayRightStyle.setRightBorderColor(borderColor);
holidayRightStyle.setBottomBorderStyle(Format::BorderThin);
holidayRightStyle.setBottomBorderColor(borderColor);
Format holidayRightStyle;
holidayRightStyle.setHorizontalAlignment(Format::AlignHCenter);
holidayRightStyle.setVerticalAlignment(Format::AlignTop);
holidayRightStyle.setPatternBackgroundColor(QColor("#EACC93"));
holidayRightStyle.setRightBorderStyle(Format::BorderThin);
holidayRightStyle.setRightBorderColor(borderColor);
holidayRightStyle.setBottomBorderStyle(Format::BorderThin);
holidayRightStyle.setBottomBorderColor(borderColor);
Format workdayLeftStyle;
workdayLeftStyle.setHorizontalAlignment(Format::AlignLeft);
@ -121,46 +120,45 @@ int calendar()
greyRightStyle.setBottomBorderColor(borderColor);
int rownum = 3;
for (int day=1; day<=31; ++day) {
for (int day = 1; day <= 31; ++day) {
QDate date(today.year(), month, day);
if (!date.isValid())
break;
xlsx.setRowHeight(rownum, 100);
int dow = date.dayOfWeek(); // 1 = Monday to 7 = Sunday
int colnum = dow*2-1;
int dow = date.dayOfWeek(); // 1 = Monday to 7 = Sunday
int colnum = dow * 2 - 1;
if (dow <= 5) { // 1,2,3,4,5
xlsx.write(rownum, colnum, day, workdayLeftStyle);
xlsx.write(rownum, colnum+1, QVariant(), workdayRightStyle);
xlsx.write(rownum, colnum + 1, QVariant(), workdayRightStyle);
} else if (dow == 6) {
xlsx.write(rownum, colnum, day, weekendLeftStyle);
xlsx.write(rownum, colnum+1, QVariant(), weekendRightStyle);
} else {
xlsx.write(rownum, colnum, day, holidayLeftStyle);
xlsx.write(rownum, colnum + 1, QVariant(), holidayRightStyle);
}
xlsx.write(rownum, colnum + 1, QVariant(), weekendRightStyle);
} else {
xlsx.write(rownum, colnum, day, holidayLeftStyle);
xlsx.write(rownum, colnum + 1, QVariant(), holidayRightStyle);
}
if (day == 1 && dow != 1) {//First day
for (int i=1; i<dow; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
if (day == 1 && dow != 1) { // First day
for (int i = 1; i < dow; ++i) {
xlsx.write(rownum, i * 2 - 1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i * 2, QVariant(), greyRightStyle);
}
} else if (day == date.daysInMonth() && dow != 7) {//Last day
for (int i=dow+1; i<=7; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
} else if (day == date.daysInMonth() && dow != 7) { // Last day
for (int i = dow + 1; i <= 7; ++i) {
xlsx.write(rownum, i * 2 - 1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i * 2, QVariant(), greyRightStyle);
}
}
if (dow == 7)
rownum++;
}
}
xlsx.saveAs("calendar1.xlsx");
//Make sure that read/write works well.
// Make sure that read/write works well.
Document xlsx2("calendar1.xlsx");
xlsx2.saveAs("calendar2.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,11 +14,10 @@ int chart()
{
//![0]
Document xlsx;
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
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
}
//![0]
@ -62,14 +61,14 @@ int chart()
Chart *scatterChart = xlsx.insertChart(83, 3, QSize(300, 300));
scatterChart->setChartType(Chart::CT_ScatterChart);
//Will generate three lines.
// Will generate three lines.
scatterChart->addSeries(CellRange("A1:A9"));
scatterChart->addSeries(CellRange("B1:B9"));
scatterChart->addSeries(CellRange("C1:C9"));
Chart *scatterChart_2 = xlsx.insertChart(83, 9, QSize(300, 300));
scatterChart_2->setChartType(Chart::CT_ScatterChart);
//Will generate two lines.
// Will generate two lines.
scatterChart_2->addSeries(CellRange("A1:C9"));
Chart *doughnutChart = xlsx.insertChart(103, 3, QSize(300, 300));
@ -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,27 +18,24 @@ QXLSX_USE_NAMESPACE
int chartExtended()
{
Document xlsx;
for (int i=1; i<10; ++i)
{
xlsx.write(1, i+1, "Pos " + QString::number(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)
{
xlsx.write(2, i+1, i*i*i); //A2:A10
xlsx.write(3, i+1, i*i); //B2:B10
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);
barChart1->setChartTitle("Test1");
// Messreihen
barChart1->addSeries(CellRange(1,1,3,10), NULL, true, true, false);
barChart1->addSeries(CellRange(1, 1, 3, 10), NULL, true, true, false);
Chart *barChart2 = xlsx.insertChart(4, 9, QSize(300, 300));
barChart2->setChartType(Chart::CT_BarChart);
@ -46,37 +43,35 @@ int chartExtended()
barChart2->setChartTitle("Test2");
barChart2->setGridlinesEnable(true);
// Messreihen
barChart2->addSeries(CellRange(1,1,3,10), NULL, true, true, true);
barChart2->addSeries(CellRange(1, 1, 3, 10), NULL, true, true, true);
Chart *barChart3 = xlsx.insertChart(24, 3, QSize(300, 300));
barChart3->setChartType(Chart::CT_BarChart);
barChart3->setChartLegend(Chart::Left);
barChart3->setChartTitle("Test3");
// Messreihen
barChart3->addSeries(CellRange(1,1,3,10));
barChart3->addSeries(CellRange(1, 1, 3, 10));
Chart *barChart4 = xlsx.insertChart(24, 9, QSize(300, 300));
barChart4->setChartType(Chart::CT_BarChart);
barChart4->setChartLegend(Chart::Top);
barChart4->setChartTitle("Test4");
// Messreihen
barChart4->addSeries(CellRange(1,1,3,10));
barChart4->addSeries(CellRange(1, 1, 3, 10));
Chart *barChart5 = xlsx.insertChart(44, 9, QSize(300, 300));
barChart5->setChartType(Chart::CT_BarChart);
barChart5->setChartLegend(Chart::Bottom);
barChart5->setChartTitle("Test5");
// Messreihen
barChart5->addSeries(CellRange(1,1,3,10));
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,16 +13,15 @@ int chartsheet()
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i)
{
xlsx.write(i, 1, i*i);
for (int i = 1; i < 10; ++i) {
xlsx.write(i, 1, i * i);
}
//![0]
//![1]
xlsx.addSheet("Chart1", AbstractSheet::ST_ChartSheet);
Chartsheet *sheet = static_cast<Chartsheet*>(xlsx.currentSheet());
Chart *barChart = sheet->chart();
Chartsheet *sheet = static_cast<Chartsheet *>(xlsx.currentSheet());
Chart *barChart = sheet->chart();
barChart->setChartType(Chart::CT_BarChart);
barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1"));
//![1]
@ -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
@ -20,7 +20,7 @@ int datavalidation()
xlsx.addDataValidation(validation);
//![1]
xlsx.saveAs("datavalidation.xlsx");
xlsx.saveAs("datavalidation.xlsx");
return 0;
}

View File

@ -1,21 +1,21 @@
// definename.cpp
#include <QtGlobal>
#include <QtCore>
#include <QDebug>
#include "xlsxdocument.h"
#include <QDebug>
#include <QtCore>
#include <QtGlobal>
QXLSX_USE_NAMESPACE
int definename()
{
//![0]
Document xlsx;
for (int i=1; i<=10; ++i) {
for (int i = 1; i <= 10; ++i) {
xlsx.write(i, 1, i);
xlsx.write(i, 2, i*i);
xlsx.write(i, 3, i*i*i);
xlsx.write(i, 2, i * i);
xlsx.write(i, 3, i * i * i);
}
//![0]
@ -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