ooo-build r11417 - in trunk: . scratch/sc-xlsutil/src



Author: kyoshida
Date: Sat Jan 26 00:28:00 2008
New Revision: 11417
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11417&view=rev

Log:
2008-01-25  Kohei Yoshida  <kyoshida novell com>

	* scratch/sc-xlsutil/src/globals.py: convert IEEE 754 bytes into double
	precision & re-wrote bytes-to-integer conversion function.
	
	* scratch/sc-xlsutil/src/record.py: simplified the record handler 
	classes.
	
	* scratch/sc-xlsutil/src/stream.py: handler for the NUMBER record, to
	display the cell address and value.


Modified:
   trunk/ChangeLog
   trunk/scratch/sc-xlsutil/src/globals.py
   trunk/scratch/sc-xlsutil/src/record.py
   trunk/scratch/sc-xlsutil/src/stream.py

Modified: trunk/scratch/sc-xlsutil/src/globals.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/globals.py	(original)
+++ trunk/scratch/sc-xlsutil/src/globals.py	Sat Jan 26 00:28:00 2008
@@ -1,5 +1,7 @@
 
-import sys
+import sys, struct
+
+class ByteConvertError(Exception): pass
 
 def output (msg):
     sys.stdout.write(msg)
@@ -21,6 +23,7 @@
 
     output("\n")
 
+
 def getSectorPos (secID, secSize):
     return 512 + secID*secSize
 
@@ -52,22 +55,37 @@
     if n == 0:
         return 0
 
-    if type(bytes[0]) == type('c'):
-        bytes = char2byte(bytes)
+    text = ''
+    for i in xrange(0, n):
+        b = bytes[i]
+        if type(b) == type(0x00):
+            b = struct.pack('B', b)
+        text += b
+
+    if n == 1:
+        # byte - 1 byte
+        return struct.unpack('b', text)[0]
+    elif n == 2:
+        # short - 2 bytes
+        return struct.unpack('h', text)[0]
+    elif n == 4:
+        # int, long - 4 bytes
+        return struct.unpack('l', text)[0]
 
-    isNegative = (bytes[-1] & 0x80) == 0x80
+    raise ByteConvertError
 
-    num, ff = 0, 0
-    for i in xrange(0, n):
-        num += bytes[i]*(256**i)
-        ff += 0xFF*(256**i)
-        i += 1
-
-    if isNegative:
-        # perform two's compliment.
-        num = -((num^ff) + 1)
 
-    return num
+def getDouble (bytes):
+    n = len(bytes)
+    if n == 0:
+        return 0.0
+    text = ''
+    for i in xrange(0, n):
+        b = bytes[i]
+        if type(b) == type(0x00):
+            b = struct.pack('B', b)
+        text += b
+    return struct.unpack('d', text)[0]
 
 
 def getUTF8FromUTF16 (bytes):

Modified: trunk/scratch/sc-xlsutil/src/record.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/record.py	(original)
+++ trunk/scratch/sc-xlsutil/src/record.py	Sat Jan 26 00:28:00 2008
@@ -1,7 +1,7 @@
 
 import globals
 
-#--------------------------------------------------------------------
+# -------------------------------------------------------------------
 # record handler classes
 
 class BaseRecordHandler(object):
@@ -24,6 +24,7 @@
     def appendLine (self, line):
         self.lines.append(line)
 
+# --------------------------------------------------------------------
 
 class BOF(BaseRecordHandler):
 
@@ -36,9 +37,6 @@
         0x0100: "Workspace"
     }
 
-    def __init__ (self, header, size, bytes):
-        BaseRecordHandler.__init__(self, header, size, bytes)
-
     def parseBytes (self):
         ver = globals.getRawBytes(self.bytes[0:2])
         dataType = globals.getSignedInt(self.bytes[2:4])
@@ -53,27 +51,30 @@
         self.appendLine("type: %s"%BOF.Type[dataType])
         self.appendLine("file history flags: " + fileHistoryFlags)
         self.appendLine("lowest Excel version: %d"%lowestExcelVer)
-        
 
 
-class CTCellContent(BaseRecordHandler):
-
-    def __init__ (self, header, size, bytes):
-        BaseRecordHandler.__init__(self, header, size, bytes)
+class Number(BaseRecordHandler):
 
     def parseBytes (self):
-        pass
+        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])
+        self.appendLine("cell position: (col: %d; row: %d)"%(col, row))
+        self.appendLine("XF record ID: %d"%xf)
+        self.appendLine("value (IEEE 754): %g"%fval)
 
-    def output (self):
-        BaseRecordHandler.output(self)
+# -------------------------------------------------------------------
+# CT - Change Tracking
 
+class CTCellContent(BaseRecordHandler):
+    pass
 
+# -------------------------------------------------------------------
+# CH - Chart
 
 class CHChart(BaseRecordHandler):
 
-    def __init__ (self, header, size, bytes):
-        BaseRecordHandler.__init__(self, header, size, bytes)
-
     def parseBytes (self):
         x = globals.getSignedInt(self.bytes[0:4])
         y = globals.getSignedInt(self.bytes[4:8])
@@ -82,7 +83,3 @@
         self.appendLine("position: (x, y) = (%d, %d)"%(x, y))
         self.appendLine("size: (width, height) = (%d, %d)"%(w, h))
         
-
-    def output (self):
-        BaseRecordHandler.output(self)
-

Modified: trunk/scratch/sc-xlsutil/src/stream.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/stream.py	(original)
+++ trunk/scratch/sc-xlsutil/src/stream.py	Sat Jan 26 00:28:00 2008
@@ -162,7 +162,7 @@
     0x01BE: ["DV", "Data Validation Criteria"],
     0x0200: ["DIMENSIONS", "Cell Table Size"],
     0x0201: ["BLANK", "Cell Value"],
-    0x0203: ["NUMBER", "Cell Value"],
+    0x0203: ["NUMBER", "Floating-Point Cell Value", record.Number],
     0x0204: ["LABEL", "Cell Value"],
     0x0205: ["BOOLERR", "Cell Value"],
     0x0207: ["STRING", "String Value of a Formula"],



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]