[ooo-build-commit] scratch/mso-dumper
Kohei Yoshida
kohei at kemper.freedesktop.org
Wed Dec 30 14:36:24 PST 2009
scratch/mso-dumper/src/xlsmodel.py | 30 ++++++++++++++++++++++--------
scratch/mso-dumper/src/xlsrecord.py | 29 ++++++++++++++++++++++-------
2 files changed, 44 insertions(+), 15 deletions(-)
New commits:
commit 160a4dd8003f4ad4cf7b55cc1a369b9c29446a4e
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Dec 30 17:35:12 2009 -0500
[xls-dump] Fetch string values from SST IDs 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 045a40d..b48c576 100644
--- a/scratch/mso-dumper/src/xlsmodel.py
+++ b/scratch/mso-dumper/src/xlsmodel.py
@@ -45,10 +45,10 @@ class Workbook(ModelBase):
return
wbglobal = self.__sheets[0]
- nd.appendChild(wbglobal.createDOM())
+ nd.appendChild(wbglobal.createDOM(self))
for i in xrange(1, n):
sheet = self.__sheets[i]
- sheetNode = sheet.createDOM()
+ sheetNode = sheet.createDOM(self)
nd.appendChild(sheetNode)
if i > 0:
data = wbglobal.getSheetData(i-1)
@@ -68,7 +68,7 @@ class SheetBase(object):
self.modelType = modelType
self.version = None
- def createDOM (self):
+ def createDOM (self, wb):
nd = node.Element('sheet')
return nd
@@ -83,14 +83,23 @@ class WorkbookGlobal(SheetBase):
SheetBase.__init__(self, SheetModelType.WorkbookGlobal)
self.__sheetData = []
+ self.__sharedStrings = []
- def createDOM (self):
+ def createDOM (self, wb):
nd = node.Element('workbook-global')
return nd
def appendSheetData (self, data):
self.__sheetData.append(data)
+ def appendSharedString (self, sst):
+ self.__sharedStrings.append(sst)
+
+ def getSharedString (self, strID):
+ if len(self.__sharedStrings) <= strID:
+ return None
+ return self.__sharedStrings[strID]
+
def getSheetData (self, i):
return self.__sheetData[i]
@@ -107,7 +116,7 @@ class Worksheet(SheetBase):
self.rows[row][col] = cell
- def createDOM (self):
+ def createDOM (self, wb):
nd = node.Element('worksheet')
nd.setAttr('version', self.version)
rows = self.rows.keys()
@@ -118,7 +127,7 @@ class Worksheet(SheetBase):
cols = self.rows[row].keys()
for col in cols:
cell = self.rows[row][col]
- cellNode = cell.createDOM()
+ cellNode = cell.createDOM(wb)
rowNode.appendChild(cellNode)
cellNode.setAttr('col', col)
return nd
@@ -138,9 +147,14 @@ class CellBase(object):
class LabelCell(CellBase):
def __init__ (self):
CellBase.__init__(self, CellModelType.Label)
+ self.strID = None
- def createDOM (self):
+ def createDOM (self, wb):
nd = node.Element('label-cell')
+ if self.strID != None:
+ sst = wb.getWorkbookGlobal().getSharedString(self.strID)
+ if sst != None:
+ nd.setAttr('value', sst.baseText)
return nd
class NumberCell(CellBase):
@@ -148,7 +162,7 @@ class NumberCell(CellBase):
CellBase.__init__(self, CellModelType.Number)
self.value = value
- def createDOM (self):
+ def createDOM (self, wb):
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 2abc69a..beb7985 100644
--- a/scratch/mso-dumper/src/xlsrecord.py
+++ b/scratch/mso-dumper/src/xlsrecord.py
@@ -404,6 +404,7 @@ class LabelSST(BaseRecordHandler):
self.__parseBytes()
sheet = model.getCurrentSheet()
cell = xlsmodel.LabelCell()
+ cell.strID = self.strId
sheet.setCell(self.col, self.row, cell)
@@ -604,15 +605,29 @@ class String(BaseRecordHandler):
class SST(BaseRecordHandler):
- def parseBytes (self):
- refCount = self.readSignedInt(4) # total number of references in workbook
- strCount = self.readSignedInt(4) # total number of unique strings.
- self.appendLine("total number of references: %d"%refCount)
- self.appendLine("total number of unique strings: %d"%strCount)
- for i in xrange(0, strCount):
+ def __parseBytes (self):
+ self.refCount = self.readSignedInt(4) # total number of references in workbook
+ self.strCount = self.readSignedInt(4) # total number of unique strings.
+ self.sharedStrings = []
+ for i in xrange(0, self.strCount):
extText, bytesRead = globals.getUnicodeRichExtText(self.bytes[self.getCurrentPos():])
self.readBytes(bytesRead) # advance current position.
- return
+ self.sharedStrings.append(extText)
+
+ def parseBytes (self):
+ self.__parseBytes()
+ self.appendLine("total number of references: %d"%self.refCount)
+ self.appendLine("total number of unique strings: %d"%self.strCount)
+ i = 0
+ for s in self.sharedStrings:
+ self.appendLine("s%d: %s"%(i, s.baseText))
+ i += 1
+
+ def fillModel (self, model):
+ self.__parseBytes()
+ wbg = model.getWorkbookGlobal()
+ for sst in self.sharedStrings:
+ wbg.appendSharedString(sst)
class Blank(BaseRecordHandler):
More information about the ooo-build-commit
mailing list