[Libreoffice-commits] mso-dumper.git: src/formula.py src/xlsrecord.py
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu Jul 25 22:43:59 PDT 2013
src/formula.py | 33 ++++++++++++++++++++++++---------
src/xlsrecord.py | 10 +++++++---
2 files changed, 31 insertions(+), 12 deletions(-)
New commits:
commit e8ddec72f52cccaca4a1700607105f52915d7a11
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jul 26 01:44:08 2013 -0400
Some improvements on formula token bytes parsing.
diff --git a/src/formula.py b/src/formula.py
index 8736485..963fb96 100644
--- a/src/formula.py
+++ b/src/formula.py
@@ -1,6 +1,6 @@
########################################################################
#
-# Copyright (c) 2010 Kohei Yoshida
+# Copyright (c) 2010-2013 Kohei Yoshida
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
@@ -31,6 +31,13 @@ import globals
class InvalidCellAddress(Exception): pass
class FormulaParserError(Exception): pass
+class ColRelU(object):
+ def __init__ (self, strm):
+ bits = strm.readUnsignedInt(2)
+ self.col = (bits & 0x3FFF)
+ self.colRelative = (bits & 0x4000) != 0
+ self.rowRelative = (bits & 0x8000) != 0
+
def toColName (colID):
if colID > 255:
globals.error("Column ID greater than 255")
@@ -174,14 +181,6 @@ class PtgMissArg(PtgBase):
def getText (self):
return '(arg missing)'
-class PtgRef(PtgBase):
- def parseBytes (self):
- self.row = self.strm.readUnsignedInt(2)
- self.col = self.strm.readUnsignedInt(2)
-
- def getText (self):
- return "(ref: row=%d, col=%d)"%(self.row, self.col)
-
class PtgMemFunc(PtgBase):
def parseBytes(self):
self.dataType = getPtgDataType(self.opcode1)
@@ -211,6 +210,13 @@ class PtgAtt(PtgBase):
def getText (self):
return "(att: %s)"%self.attName
+class PtgArray(PtgBase):
+ def parseBytes (self):
+ self.strm.readBytes(7)
+
+ def getText (self):
+ return "(array)"
+
class PtgName(PtgBase):
def parseBytes (self):
self.nameIdx = self.strm.readUnsignedInt(4)
@@ -218,6 +224,13 @@ class PtgName(PtgBase):
def getText (self):
return "(name: %d)"%self.nameIdx
+class PtgRef(PtgBase):
+ def parseBytes (self):
+ self.row = self.strm.readUnsignedInt(2)
+ self.col = ColRelU(self.strm)
+
+ def getText (self):
+ return "(ref: row=%d,col=%d,rowRelative=%d,colRelative=%d)"%(self.row, self.col.col, self.col.rowRelative, self.col.colRelative)
class PtgNameX(PtgBase):
def parseBytes (self):
@@ -670,7 +683,9 @@ _tokenMap = {
0x24: PtgRef,
0x29: PtgMemFunc,
0x3B: _Area3d,
+ 0x40: PtgArray,
0x43: PtgName,
+ 0x44: PtgRef,
0x59: PtgNameX,
0x5B: _Area3d,
0x7B: _Area3d,
diff --git a/src/xlsrecord.py b/src/xlsrecord.py
index 90cb699..ecc4029 100644
--- a/src/xlsrecord.py
+++ b/src/xlsrecord.py
@@ -1185,10 +1185,14 @@ class Array(BaseRecordHandler):
self.__parseBytes()
self.appendLine("range: %s"%self.ref.toString())
self.appendLineBoolean("always calc", self.alwaysCalc)
- fparser = formula.FormulaParser(self.header, self.tokens)
- fparser.parse()
self.appendLine("formula bytes: %s"%globals.getRawBytes(self.tokens, True, False))
- self.appendLine("formula string: %s"%fparser.getText())
+ try:
+ fparser = formula.FormulaParser(self.header, self.tokens)
+ fparser.parse()
+ self.appendLine("formula string: %s"%fparser.getText())
+ except formula.FormulaParserError:
+ self.appendLine("formula string: <error parsing token bytes>")
+
class Label(BaseRecordHandler):
More information about the Libreoffice-commits
mailing list