mirror of
https://github.com/QtExcel/QXlsx.git
synced 2025-01-16 04:42:53 +08:00
testing shared formula
This commit is contained in:
parent
9f2506faf0
commit
e66643464f
26
IssueTest/WriteSharedFormula.py
Normal file
26
IssueTest/WriteSharedFormula.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# WriteSharedFormula.py
|
||||
|
||||
# Installation: pip install XlsXcessive
|
||||
# https://pypi.org/project/XlsXcessive/
|
||||
|
||||
import io
|
||||
|
||||
from xlsxcessive import xlsx
|
||||
from xlsxcessive.worksheet import Cell
|
||||
|
||||
def main():
|
||||
workbook = xlsx.Workbook()
|
||||
sheet1 = workbook.new_sheet('Sheet 1')
|
||||
sheet1.cell('B1', value=7)
|
||||
sheet1.cell('C1', value=8)
|
||||
sheet1.cell('D1', value=9)
|
||||
formula = sheet1.formula('B1 + C1', shared=True)
|
||||
sheet1.cell('D2', formula) # master
|
||||
sheet1.cell('E2', formula) # shared, references the master formula
|
||||
xlsx.save(workbook, 'test.xlsx') # save local file
|
||||
|
||||
if __name__ == "__main__":
|
||||
# execute only if run as a script
|
||||
main()
|
@ -27,7 +27,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
QVector<QVariant> testParams;
|
||||
int ret = test(testParams);
|
||||
qDebug() << "test return value : " << ret;
|
||||
// qDebug() << "test return value : " << ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
2
IssueTest/run.cmd
Normal file
2
IssueTest/run.cmd
Normal file
@ -0,0 +1,2 @@
|
||||
python WriteSharedFormula.py
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
@ -19,14 +20,24 @@ using namespace std;
|
||||
#include "xlsxworkbook.h"
|
||||
using namespace QXlsx;
|
||||
|
||||
int test(QVector<QVariant> params)
|
||||
int test( QVector<QVariant> params )
|
||||
{
|
||||
qDebug() << " current path : " << QDir::currentPath();
|
||||
|
||||
Document doc( "test.xlsx" );
|
||||
if ( ! doc.load() )
|
||||
{
|
||||
qDebug() << "Failed to load 'test.xlsx'";
|
||||
return (-1);
|
||||
}
|
||||
qDebug() << "load 'test2.xlsx'";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ( ! doc.saveAs( "test2.xlsx" ) )
|
||||
{
|
||||
qDebug() << "Failed to save 'test2.xlsx'";
|
||||
return (-2);
|
||||
}
|
||||
qDebug() << "save 'test2.xlsx'";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
BIN
IssueTest/test.xlsx
Normal file
BIN
IssueTest/test.xlsx
Normal file
Binary file not shown.
@ -1,27 +1,5 @@
|
||||
/****************************************************************************
|
||||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
|
||||
** All right reserved.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining
|
||||
** a copy of this software and associated documentation files (the
|
||||
** "Software"), to deal in the Software without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Software, and to
|
||||
** permit persons to whom the Software is furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be
|
||||
** included in all copies or substantial portions of the Software.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
**
|
||||
****************************************************************************/
|
||||
// xlsxworkbook.cpp
|
||||
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxworkbook_p.h"
|
||||
#include "xlsxsharedstrings_p.h"
|
||||
@ -39,6 +17,7 @@
|
||||
#include <QFile>
|
||||
#include <QBuffer>
|
||||
#include <QDir>
|
||||
#include <QtDebug>
|
||||
|
||||
QT_BEGIN_NAMESPACE_XLSX
|
||||
|
||||
@ -560,13 +539,20 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
|
||||
QXmlStreamReader reader(device);
|
||||
while (!reader.atEnd()) {
|
||||
QXmlStreamReader::TokenType token = reader.readNext();
|
||||
if (token == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("sheet")) {
|
||||
if (token == QXmlStreamReader::StartElement)
|
||||
{
|
||||
if (reader.name() == QLatin1String("sheet"))
|
||||
{
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
|
||||
const QString name = attributes.value(QLatin1String("name")).toString();
|
||||
|
||||
int sheetId = attributes.value(QLatin1String("sheetId")).toString().toInt();
|
||||
|
||||
const QString rId = attributes.value(QLatin1String("r:id")).toString();
|
||||
|
||||
const QStringRef &stateString = attributes.value(QLatin1String("state"));
|
||||
|
||||
AbstractSheet::SheetState state = AbstractSheet::SS_Visible;
|
||||
if (stateString == QLatin1String("hidden"))
|
||||
state = AbstractSheet::SS_Hidden;
|
||||
@ -577,29 +563,47 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
|
||||
|
||||
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");
|
||||
{
|
||||
qWarning() << "unknown sheet type : " << relationship.type ;
|
||||
}
|
||||
|
||||
AbstractSheet *sheet = addSheet(name, sheetId, type);
|
||||
sheet->setSheetState(state);
|
||||
const QString fullPath = QDir::cleanPath(splitPath(filePath())[0] +QLatin1String("/")+ relationship.target);
|
||||
sheet->setFilePath(fullPath);
|
||||
} else if (reader.name() == QLatin1String("workbookPr")) {
|
||||
}
|
||||
else if (reader.name() == QLatin1String("workbookPr"))
|
||||
{
|
||||
QXmlStreamAttributes attrs = reader.attributes();
|
||||
if (attrs.hasAttribute(QLatin1String("date1904")))
|
||||
d->date1904 = true;
|
||||
} else if (reader.name() == QLatin1String("bookviews")) {
|
||||
while (!(reader.name() == QLatin1String("bookviews") && reader.tokenType() == QXmlStreamReader::EndElement)) {
|
||||
}
|
||||
else if (reader.name() == QLatin1String("bookviews"))
|
||||
{
|
||||
while (!(reader.name() == QLatin1String("bookviews") &&
|
||||
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")).toString().toInt();
|
||||
@ -616,7 +620,9 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (reader.name() == QLatin1String("externalReference")) {
|
||||
}
|
||||
else if (reader.name() == QLatin1String("externalReference"))
|
||||
{
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
const QString rId = attributes.value(QLatin1String("r:id")).toString();
|
||||
XlsxRelationship relationship = d->relationships->getRelationshipById(rId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user