[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/filters/kspread/excel
From: Marijn Kruisselbrink <m.kruisselbrink () student ! tue ! nl>
Date: 2010-08-29 20:55:15
Message-ID: 20100829205515.D8125AC876 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1169666 by mkruisselbrink:
properly save cell and area references (references to other sheets are still broken)
M +20 -7 export/ExcelExport.cpp
M +1 -1 export/ExcelExport.h
M +30 -14 sidewinder/formulas.cpp
M +4 -2 sidewinder/formulas.h
--- trunk/koffice/filters/kspread/excel/export/ExcelExport.cpp #1169665:1169666
@@ -35,6 +35,7 @@
#include <Formula.h>
#include <Map.h>
#include <Sheet.h>
+#include <Region.h>
#include <RowColumnFormat.h>
#include <ValueStorage.h>
#include <kspread_limits.h>
@@ -381,7 +382,7 @@
fr.setResult(Value::empty());
}
KSpread::Formula f = cell.formula();
- QList<FormulaToken> tokens = compileFormula(f.tokens());
+ QList<FormulaToken> tokens = compileFormula(f.tokens(), sheet);
foreach (const FormulaToken& t, tokens) {
fr.addToken(t);
}
@@ -552,7 +553,7 @@
return prec;
}
-QList<FormulaToken> ExcelExport::compileFormula(const KSpread::Tokens &tokens) const
+QList<FormulaToken> ExcelExport::compileFormula(const KSpread::Tokens &tokens, \
KSpread::Sheet* sheet) const {
QList<FormulaToken> codes;
@@ -629,11 +630,23 @@
(tokenType == KSpread::Token::Identifier)) {
syntaxStack.push(token);
- if (tokenType == KSpread::Token::Cell)
- codes.append(FormulaToken::createRef(token.text()));
- else if (tokenType == KSpread::Token::Range)
- codes.append(FormulaToken::createArea(token.text()));
- else {
+ if (tokenType == KSpread::Token::Cell) {
+ const KSpread::Region region(token.text(), d->inputDoc->map(), \
sheet); + if (!region.isValid() || !region.isSingular()) {
+ codes.append(FormulaToken::createRefErr());
+ } else {
+ KSpread::Region::Element* e = *region.constBegin();
+ codes.append(FormulaToken::createRef(e->rect().topLeft() - \
QPoint(1, 1), e->isRowFixed(), e->isColumnFixed())); + }
+ } else if (tokenType == KSpread::Token::Range) {
+ const KSpread::Region region(token.text(), d->inputDoc->map(), \
sheet); + if (!region.isValid()) {
+ codes.append(FormulaToken::createAreaErr());
+ } else {
+ KSpread::Region::Element* e = *region.constBegin();
+ codes.append(FormulaToken::createArea(e->rect().adjusted(-1, -1, \
-1, -1), e->isTopFixed(), e->isBottomFixed(), e->isLeftFixed(), e->isRightFixed())); \
+ } + } else {
// TODO
// codes.append(FormulaToken(FormulaToken::MissArg));
}
--- trunk/koffice/filters/kspread/excel/export/ExcelExport.h #1169665:1169666
@@ -49,7 +49,7 @@
virtual KoFilter::ConversionStatus convert(const QByteArray& from, const \
QByteArray& to);
- QList<Swinder::FormulaToken> compileFormula(const KSpread::Tokens& tokens) \
const; + QList<Swinder::FormulaToken> compileFormula(const KSpread::Tokens& \
tokens, KSpread::Sheet* sheet) const;
void convertSheet(KSpread::Sheet* sheet, const QHash<QString, unsigned>& sst);
void buildStringTable(KSpread::Sheet* sheet, Swinder::SSTRecord& sst, \
QHash<QString, unsigned>& stringTable);
--- trunk/koffice/filters/kspread/excel/sidewinder/formulas.cpp #1169665:1169666
@@ -124,17 +124,17 @@
return t;
}
-FormulaToken FormulaToken::createRef(const QString &cell)
+FormulaToken FormulaToken::createRef(const QPoint& pos, bool rowFixed, bool \
colFixed) {
FormulaToken t(Ref);
QBuffer b;
b.open(QIODevice::WriteOnly);
QDataStream ds(&b);
ds.setByteOrder(QDataStream::LittleEndian);
- unsigned row = 1;
- unsigned col = 1;
- bool rowRel = true;
- bool colRel = true;
+ unsigned row = pos.y();
+ unsigned col = pos.x();
+ bool rowRel = !rowFixed;
+ bool colRel = !colFixed;
if (rowRel) col |= 0x4000;
if (colRel) col |= 0x8000;
@@ -144,21 +144,29 @@
return t;
}
-FormulaToken FormulaToken::createArea(const QString &cell)
+FormulaToken FormulaToken::createRefErr()
{
+ FormulaToken t(RefErr);
+ quint32 zero = 0;
+ t.setData(4, reinterpret_cast<unsigned char*>(&zero));
+ return t;
+}
+
+FormulaToken FormulaToken::createArea(const QRect& area, bool topFixed, bool \
bottomFixed, bool leftFixed, bool rightFixed) +{
FormulaToken t(Area);
QBuffer b;
b.open(QIODevice::WriteOnly);
QDataStream ds(&b);
ds.setByteOrder(QDataStream::LittleEndian);
- unsigned row1 = 1;
- unsigned col1 = 1;
- bool rowRel1 = true;
- bool colRel1 = true;
- unsigned row2 = 3;
- unsigned col2 = 4;
- bool rowRel2 = true;
- bool colRel2 = true;
+ unsigned row1 = area.top();
+ unsigned col1 = area.left();
+ bool rowRel1 = !topFixed;
+ bool colRel1 = !leftFixed;
+ unsigned row2 = area.bottom();
+ unsigned col2 = area.right();
+ bool rowRel2 = !bottomFixed;
+ bool colRel2 = !rightFixed;
if (rowRel1) col1 |= 0x4000;
if (colRel1) col1 |= 0x8000;
@@ -172,6 +180,14 @@
return t;
}
+FormulaToken FormulaToken::createAreaErr()
+{
+ FormulaToken t(AreaErr);
+ quint64 zero = 0;
+ t.setData(8, reinterpret_cast<unsigned char*>(&zero));
+ return t;
+}
+
FormulaToken FormulaToken::createFunc(const QString &func, unsigned argCount)
{
unsigned paramCount = functionParams(func);
--- trunk/koffice/filters/kspread/excel/sidewinder/formulas.h #1169665:1169666
@@ -102,8 +102,10 @@
static FormulaToken createBool(bool value);
static FormulaToken createNum(double value);
static FormulaToken createStr(const QString& value);
- static FormulaToken createRef(const QString& cell);
- static FormulaToken createArea(const QString& area);
+ static FormulaToken createRef(const QPoint& pos, bool rowFixed, bool colFixed);
+ static FormulaToken createRefErr();
+ static FormulaToken createArea(const QRect& area, bool topFixed, bool \
bottomFixed, bool leftFixed, bool rightFixed); + static FormulaToken \
createAreaErr();
static FormulaToken createFunc(const QString& func, unsigned argCount);
// token id, excluding token class
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic