[ooo-build-commit] scratch/mso-dumper

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Dec 30 14:55:08 PST 2009


 scratch/mso-dumper/src/xlsmodel.py  |   20 +++++++++++++---
 scratch/mso-dumper/src/xlsrecord.py |   45 +++++++++++++++++++++---------------
 2 files changed, 44 insertions(+), 21 deletions(-)

New commits:
commit 09e1ac2e61aa64cbbb2b9513207fd8c53d95b37c
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Dec 30 17:54:26 2009 -0500

    [xls-dump] Handle FORMULA records in canonical XML mode.
    
    * scratch/mso-dumper/src/xlsmodel.py:
    * scratch/mso-dumper/src/xlsrecord.py:

diff --git a/scratch/mso-dumper/src/xlsmodel.py b/scratch/mso-dumper/src/xlsmodel.py
index b48c576..538b7c6 100644
--- a/scratch/mso-dumper/src/xlsmodel.py
+++ b/scratch/mso-dumper/src/xlsmodel.py
@@ -45,7 +45,7 @@ class Workbook(ModelBase):
             return
 
         wbglobal = self.__sheets[0]
-        nd.appendChild(wbglobal.createDOM(self))
+#       nd.appendChild(wbglobal.createDOM(self))
         for i in xrange(1, n):
             sheet = self.__sheets[i]
             sheetNode = sheet.createDOM(self)
@@ -134,8 +134,9 @@ class Worksheet(SheetBase):
 
 
 class CellModelType:
-    Label = 0
-    Number = 1
+    Label   = 0
+    Number  = 1
+    Formula = 2
     Unknown = 999
 
 
@@ -157,6 +158,7 @@ class LabelCell(CellBase):
                 nd.setAttr('value', sst.baseText)
         return nd
 
+
 class NumberCell(CellBase):
     def __init__ (self, value):
         CellBase.__init__(self, CellModelType.Number)
@@ -167,3 +169,15 @@ class NumberCell(CellBase):
         nd.setAttr('value', self.value)
         return nd
 
+
+class FormulaCell(CellBase):
+    def __init__ (self):
+        CellBase.__init__(self, CellModelType.Formula)
+        self.tokens = None
+
+    def createDOM (self, wb):
+        nd = node.Element('formula-cell')
+        if self.tokens != None:
+            s = globals.getRawBytes(self.tokens, True, False)
+            nd.setAttr('token-bytes', s)
+        return nd
diff --git a/scratch/mso-dumper/src/xlsrecord.py b/scratch/mso-dumper/src/xlsrecord.py
index beb7985..a9ef316 100644
--- a/scratch/mso-dumper/src/xlsrecord.py
+++ b/scratch/mso-dumper/src/xlsrecord.py
@@ -277,31 +277,40 @@ class FilePass(BaseRecordHandler):
 
 class Formula(BaseRecordHandler):
 
-    def parseBytes (self):
-        row  = globals.getSignedInt(self.bytes[0:2])
-        col  = globals.getSignedInt(self.bytes[2:4])
-        xf   = globals.getSignedInt(self.bytes[4:6])
-        fval = globals.getDouble(self.bytes[6:14])
+    def __parseBytes (self):
+        self.row = self.readUnsignedInt(2)
+        self.col = self.readUnsignedInt(2)
+        self.xf = self.readUnsignedInt(2)
+        self.fval = self.readDouble()
 
-        flags          = globals.getSignedInt(self.bytes[14:16])
-        recalc         = (flags & 0x0001) != 0
-        calcOnOpen     = (flags & 0x0002) != 0
-        sharedFormula  = (flags & 0x0008) != 0
+        flags = self.readUnsignedInt(2)
+        self.recalc         = (flags & 0x0001) != 0
+        self.calcOnOpen     = (flags & 0x0002) != 0
+        self.sharedFormula  = (flags & 0x0008) != 0
+        self.tokens = self.readRemainingBytes()
 
-        tokens = self.bytes[20:]
-        fparser = formula.FormulaParser(self.header, tokens)
+    def parseBytes (self):
+        self.__parseBytes()
+        fparser = formula.FormulaParser(self.header, self.tokens)
         fparser.parse()
         ftext = fparser.getText()
 
-        self.appendCellPosition(col, row)
-        self.appendLine("XF record ID: %d"%xf)
-        self.appendLine("formula result: %g"%fval)
-        self.appendLine("recalculate always: %d"%recalc)
-        self.appendLine("calculate on open: %d"%calcOnOpen)
-        self.appendLine("shared formula: %d"%sharedFormula)
-        self.appendLine("formula bytes: %s"%globals.getRawBytes(tokens, True, False))
+        self.appendCellPosition(self.col, self.row)
+        self.appendLine("XF record ID: %d"%self.xf)
+        self.appendLine("formula result: %g"%self.fval)
+        self.appendLine("recalculate always: %d"%self.recalc)
+        self.appendLine("calculate on open: %d"%self.calcOnOpen)
+        self.appendLine("shared formula: %d"%self.sharedFormula)
+        self.appendLine("formula bytes: %s"%globals.getRawBytes(self.tokens, True, False))
         self.appendLine("tokens: "+ftext)
 
+    def fillModel (self, model):
+        self.__parseBytes()
+        sheet = model.getCurrentSheet()
+        cell = xlsmodel.FormulaCell()
+        cell.tokens = self.tokens
+        sheet.setCell(self.col, self.row, cell)
+
 
 class Array(BaseRecordHandler):
 


More information about the ooo-build-commit mailing list