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

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Dec 30 13:55:50 PST 2009


 scratch/mso-dumper/src/globals.py   |    3 +
 scratch/mso-dumper/src/node.py      |    2 
 scratch/mso-dumper/src/xlsmodel.py  |   22 +++++++++
 scratch/mso-dumper/src/xlsrecord.py |   80 ++++++++++++++++++++++++++++--------
 scratch/mso-dumper/src/xlsstream.py |    2 
 5 files changed, 91 insertions(+), 18 deletions(-)

New commits:
commit a9b4cc0e0c8a57d11855567aa5cae0efda43d21a
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Dec 30 16:55:10 2009 -0500

    [xls-dump] Handle MULRK records.
    
    * scratch/mso-dumper/src/globals.py:
    * scratch/mso-dumper/src/node.py:
    * scratch/mso-dumper/src/xlsmodel.py:
    * scratch/mso-dumper/src/xlsrecord.py:
    * scratch/mso-dumper/src/xlsstream.py:

diff --git a/scratch/mso-dumper/src/globals.py b/scratch/mso-dumper/src/globals.py
index e2f9969..8aa41e1 100644
--- a/scratch/mso-dumper/src/globals.py
+++ b/scratch/mso-dumper/src/globals.py
@@ -46,6 +46,9 @@ class ByteStream(object):
         self.pos = 0
         self.size = len(bytes)
 
+    def getSize (self):
+        return self.size
+
     def readBytes (self, length):
         r = self.bytes[self.pos:self.pos+length]
         self.pos += length
diff --git a/scratch/mso-dumper/src/node.py b/scratch/mso-dumper/src/node.py
index ecaf2ad..35158dc 100644
--- a/scratch/mso-dumper/src/node.py
+++ b/scratch/mso-dumper/src/node.py
@@ -128,6 +128,8 @@ def convertAttrValue (val):
             val = "false"
     elif type(val) == type(0):
         val = "%d"%val
+    elif type(val) == type(0.0):
+        val = "%g"%val
 
     return val
 
diff --git a/scratch/mso-dumper/src/xlsmodel.py b/scratch/mso-dumper/src/xlsmodel.py
index 06b4eab..045a40d 100644
--- a/scratch/mso-dumper/src/xlsmodel.py
+++ b/scratch/mso-dumper/src/xlsmodel.py
@@ -115,11 +115,18 @@ class Worksheet(SheetBase):
         for row in rows:
             rowNode = nd.appendElement('row')
             rowNode.setAttr('id', row)
+            cols = self.rows[row].keys()
+            for col in cols:
+                cell = self.rows[row][col]
+                cellNode = cell.createDOM()
+                rowNode.appendChild(cellNode)
+                cellNode.setAttr('col', col)
         return nd
 
 
 class CellModelType:
     Label = 0
+    Number = 1
     Unknown = 999
 
 
@@ -127,7 +134,22 @@ class CellBase(object):
     def __init__ (self, modelType):
         self.modelType = modelType
 
+
 class LabelCell(CellBase):
     def __init__ (self):
         CellBase.__init__(self, CellModelType.Label)
 
+    def createDOM (self):
+        nd = node.Element('label-cell')
+        return nd
+
+class NumberCell(CellBase):
+    def __init__ (self, value):
+        CellBase.__init__(self, CellModelType.Number)
+        self.value = value
+
+    def createDOM (self):
+        nd = node.Element('number-cell')
+        nd.setAttr('value', self.value)
+        return nd
+
diff --git a/scratch/mso-dumper/src/xlsrecord.py b/scratch/mso-dumper/src/xlsrecord.py
index 5b2e544..2abc69a 100644
--- a/scratch/mso-dumper/src/xlsrecord.py
+++ b/scratch/mso-dumper/src/xlsrecord.py
@@ -18,6 +18,29 @@ def getValueOrUnknown (list, idx, errmsg='(unknown)'):
 
     return errmsg
 
+
+def decodeRK (rkval):
+    multi100  = ((rkval & 0x00000001) != 0)
+    signedInt = ((rkval & 0x00000002) != 0)
+    realVal   = (rkval & 0xFFFFFFFC)
+
+    if signedInt:
+        # for integer, perform right-shift by 2 bits.
+        realVal = realVal/4
+    else:
+        # for floating-point, convert the value back to the bytes,
+        # pad the bytes to make it 8-byte long, and convert it back
+        # to the numeric value.
+        tmpBytes = struct.pack('<L', realVal)
+        tmpBytes = struct.pack('xxxx') + tmpBytes
+        realVal = struct.unpack('<d', tmpBytes)[0]
+
+    if multi100:
+        realVal /= 100
+
+    return realVal
+
+
 class BaseRecordHandler(globals.ByteStream):
 
     def __init__ (self, header, size, bytes, strmData):
@@ -384,6 +407,45 @@ class LabelSST(BaseRecordHandler):
         sheet.setCell(self.col, self.row, cell)
 
 
+class MulRK(BaseRecordHandler):
+    class RKRec(object):
+        def __init__ (self):
+            self.xfIdx = None    # XF record index
+            self.number = None   # RK number
+
+    def __parseBytes (self):
+        self.row = self.readUnsignedInt(2)
+        self.col1 = self.readUnsignedInt(2)
+        self.rkrecs = []
+        rkCount = (self.getSize() - self.getCurrentPos() - 2) / 6
+        for i in xrange(0, rkCount):
+            rec = MulRK.RKRec()
+            rec.xfIdx = self.readUnsignedInt(2)
+            rec.number = self.readUnsignedInt(4)
+            self.rkrecs.append(rec)
+
+        self.col2 = self.readUnsignedInt(2)
+
+    def parseBytes (self):
+        self.__parseBytes()
+        self.appendLine("row: %d"%self.row)
+        self.appendLine("columns: %d - %d"%(self.col1, self.col2))
+        for rkrec in self.rkrecs:
+            self.appendLine("XF record ID: %d"%rkrec.xfIdx)
+            self.appendLine("RK number: %g"%decodeRK(rkrec.number))
+
+    def fillModel (self, model):
+        self.__parseBytes()
+        sheet = model.getCurrentSheet()
+        n = len(self.rkrecs)
+        for i in xrange(0, n):
+            rkrec = self.rkrecs[i]
+            col = self.col1 + i
+            cell = xlsmodel.NumberCell(decodeRK(rkrec.number))
+            sheet.setCell(col, self.row, cell)
+
+
+
 class Number(BaseRecordHandler):
 
     def parseBytes (self):
@@ -519,23 +581,7 @@ class RK(BaseRecordHandler):
         xf  = globals.getSignedInt(self.bytes[4:6])
 
         rkval = globals.getSignedInt(self.bytes[6:10])
-        multi100  = ((rkval & 0x00000001) != 0)
-        signedInt = ((rkval & 0x00000002) != 0)
-        realVal   = (rkval & 0xFFFFFFFC)
-
-        if signedInt:
-            # for integer, perform right-shift by 2 bits.
-            realVal = realVal/4
-        else:
-            # for floating-point, convert the value back to the bytes,
-            # pad the bytes to make it 8-byte long, and convert it back
-            # to the numeric value.
-            tmpBytes = struct.pack('<L', realVal)
-            tmpBytes = struct.pack('xxxx') + tmpBytes
-            realVal = struct.unpack('<d', tmpBytes)[0]
-
-        if multi100:
-            realVal /= 100
+        realVal = decodeRK(rkval)
 
         self.appendCellPosition(col, row)
         self.appendLine("XF record ID: %d"%xf)
diff --git a/scratch/mso-dumper/src/xlsstream.py b/scratch/mso-dumper/src/xlsstream.py
index adca9f3..7fc127b 100644
--- a/scratch/mso-dumper/src/xlsstream.py
+++ b/scratch/mso-dumper/src/xlsstream.py
@@ -100,7 +100,7 @@ recData = {
     0x00B8: ["DOCROUTE", "Routing Slip Information"],
     0x00B9: ["RECIPNAME", "Recipient Name"],
     0x00BC: ["SHRFMLA", "Shared Formula"],
-    0x00BD: ["MULRK", "Multiple RK Cells"],
+    0x00BD: ["MULRK", "Multiple RK Cells", xlsrecord.MulRK],
     0x00BE: ["MULBLANK", "Multiple Blank Cells"],
     0x00C1: ["MMS", "ADDMENU/DELMENU Record Group Count"],
     0x00C2: ["ADDMENU", "Menu Addition"],


More information about the ooo-build-commit mailing list