[Libreoffice-commits] .: src/xlsrecord.py src/xlsstream.py

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Feb 10 20:54:34 PST 2012


 src/xlsrecord.py |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 src/xlsstream.py |    4 ++-
 2 files changed, 54 insertions(+), 6 deletions(-)

New commits:
commit b8394504efdb3437d48c3ae9783c5969b036732f
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Fri Feb 10 23:54:08 2012 -0500

    Handler for SXDBB record.
    
    This requires storing unique values for each field item in order
    to print them in the SXDBB records.

diff --git a/src/xlsrecord.py b/src/xlsrecord.py
index e2c7383..d75ab55 100644
--- a/src/xlsrecord.py
+++ b/src/xlsrecord.py
@@ -133,6 +133,16 @@ def dumpFrtHeader(header):
     return {'rt': header.rt,
             'flags': header.flags}
 
+
+class PivotField(object):
+    """Data about pivot cache field.
+
+This is to be stored in the persistent stream data, to be used in the SXDBB
+records."""
+    def __init__ (self):
+        self.hasMoreThan255 = False
+        self.values = []
+
 class BaseRecordHandler(globals.ByteStream):
 
     def __init__ (self, header, size, bytes, strmData):
@@ -2917,6 +2927,24 @@ class SXDb(BaseRecordHandler):
         self.appendLine("changed by: %s"%changedBy)
 
 
+class SXDBB(BaseRecordHandler):
+
+    def __parseBytes (self):
+        self.items = []
+        for fld in self.strmData.pivotCacheFields:
+            if fld.hasMoreThan255:
+                # read 2 bytes
+                idx = self.readUnsignedInt(2)
+            else:
+                idx = self.readUnsignedInt(1)
+            s = fld.values[idx]
+            self.items.append(s)
+
+    def parseBytes (self):
+        self.__parseBytes()
+        for item in self.items:
+            self.appendLine(item)
+
 class SXDbEx(BaseRecordHandler):
 
     def parseBytes (self):
@@ -2935,6 +2963,8 @@ class SXDtr(BaseRecordHandler):
         self.hr = self.readUnsignedInt(1)
         self.min = self.readUnsignedInt(1)
         self.sec = self.readUnsignedInt(1)
+        s = "%d-%d-%dT%2.2d-%2.2d-%2.2d"%(self.yr, self.mon, self.dom, self.hr, self.min, self.sec)
+        self.strmData.pivotCacheFields[-1].values.append(s)
 
     def parseBytes (self):
         self.__parseBytes()
@@ -3016,6 +3046,13 @@ class SXFDB(BaseRecordHandler):
         self.catm = self.readUnsignedInt(2)
         self.stFieldName = self.readXLUnicodeString()
 
+        if self.fAllAtoms:
+            # this cached field has a collection of items in the following
+            # SXDBB records.
+            obj = PivotField()
+            obj.hasMoreThan255 = self.fShortIitms
+            self.strmData.pivotCacheFields.append(obj)
+
     def parseBytes (self):
         self.__parseBytes()
         self.appendLineBoolean("collection of items", self.fAllAtoms)
@@ -3481,9 +3518,14 @@ class PivotQueryTableEx(BaseRecordHandler):
 
 
 class SXDouble(BaseRecordHandler):
+
+    def __parseBytes (self):
+        self.val = self.readDouble()
+        self.strmData.pivotCacheFields[-1].values.append("%g"%self.val)
+
     def parseBytes (self):
-        val = self.readDouble()
-        self.appendLine("value: %g"%val)
+        self.__parseBytes()
+        self.appendLine("value: %g"%self.val)
 
 
 class SXBoolean(BaseRecordHandler):
@@ -3501,10 +3543,14 @@ class SXInteger(BaseRecordHandler):
 
 
 class SXString(BaseRecordHandler):
+
+    def __parseBytes (self):
+        self.text = self.readXLUnicodeString()
+        self.strmData.pivotCacheFields[-1].values.append(self.text)
+
     def parseBytes (self):
-        textLen = self.readUnsignedInt(2)
-        text, textLen = globals.getRichText(self.readRemainingBytes(), textLen)
-        self.appendLine("value: %s"%text)
+        self.__parseBytes()
+        self.appendLineString("value", self.text)
 
 # -------------------------------------------------------------------
 # CT - Change Tracking
diff --git a/src/xlsstream.py b/src/xlsstream.py
index 1292994..44695bf 100644
--- a/src/xlsstream.py
+++ b/src/xlsstream.py
@@ -137,7 +137,7 @@ recData = {
     0x00C5: ["SXDI", "Data Item", xlsrecord.SXDataItem],
     0x00C6: ["SXDB", "PivotTable Cache Data", xlsrecord.SXDb],
     0x00C7: ["SXFDB", "Pivot Field", xlsrecord.SXFDB],
-    0x00C8: ["SXINDEXLIST", "Indices to Source Data"],
+    0x00C8: ["SXDBB", "Indices to Source Data", xlsrecord.SXDBB],
     0x00C9: ["SXDOUBLE", "Double Value", xlsrecord.SXDouble],
     0x00CA: ["SXBOOLEAN", "Boolean Value", xlsrecord.SXBoolean],
     0x00CB: ["SXERROR", "Error Code", xlsrecord.SXError],
@@ -319,11 +319,13 @@ recDataRev = {
     0x0151: ["EONB*", "Change Track End of Nested Block"]
 }
 
+
 class StreamData(object):
     """run-time stream data."""
     def __init__ (self):
         self.encrypted = False
         self.pivotCacheIDs = {}
+        self.pivotCacheFields = []
 
     def appendPivotCacheId (self, newId):
         # must be 4-digit with leading '0's.


More information about the Libreoffice-commits mailing list