diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-04-15 20:04:17 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-04-15 20:04:48 -0400 |
commit | 9876044485a9227d95cae073f1b4b468646dfd0e (patch) | |
tree | 82e7a45c30ed9d002cedfbf4fe06d1495d58f8bd /scratch | |
parent | 3d4e33a0de7f6780a1f03d75b5caccefb1f9b5fc (diff) |
[xls-dump] Display data validation information in cXML mode.
* scratch/mso-dumper/src/xlsmodel.py:
* scratch/mso-dumper/src/xlsrecord.py:
Diffstat (limited to 'scratch')
-rw-r--r-- | scratch/mso-dumper/src/xlsmodel.py | 73 | ||||
-rw-r--r-- | scratch/mso-dumper/src/xlsrecord.py | 39 |
2 files changed, 102 insertions, 10 deletions
diff --git a/scratch/mso-dumper/src/xlsmodel.py b/scratch/mso-dumper/src/xlsmodel.py index 915c66f12..50b2af348 100644 --- a/scratch/mso-dumper/src/xlsmodel.py +++ b/scratch/mso-dumper/src/xlsmodel.py @@ -319,6 +319,8 @@ class Worksheet(SheetBase): self.__shapes = [] self.__lastCell = None self.__condFormats = [] + self.__dataValidations = [] + def addShape (self, obj): self.__shapes.append(obj) @@ -362,6 +364,9 @@ class Worksheet(SheetBase): def getLastCondFormat (self): return self.__condFormats[-1] + def setDataValidation (self, dv): + self.__dataValidations.append(dv) + def createDOM (self, wb): nd = node.Element('worksheet') nd.setAttr('version', self.version) @@ -391,6 +396,7 @@ class Worksheet(SheetBase): self.__appendRowHeightNode(wb, nd) # row heights self.__appendShapesNode(wb, nd) # drawing objects self.__appendCondFormatNode(wb, nd) # conditional formatting + self.__appendDataValidationNode(wb, nd) # conditional formatting return nd def __appendRowHeightNode (self, wb, baseNode): @@ -465,6 +471,16 @@ class Worksheet(SheetBase): objElem = elem.appendElement('cond-format') objElem.setAttr('format-range', "%s"%obj.formatRange.getName()) + def __appendDataValidationNode (self, wb, baseNode): + n = len(self.__dataValidations) + if n == 0: + return + + elem = baseNode.appendElement('data-validations') + for obj in self.__dataValidations: + child = obj.createDOM(wb) + elem.appendChild(child) + class CellBase(object): @@ -552,3 +568,60 @@ class CondFormat(object): def __init__ (self): self.formatRange = None + +class DataValidation(object): + + def __init__ (self, ranges): + self.ranges = ranges # list of formula.CellRange + self.valueType = None + self.errorStyle = None + self.operator = None + self.strLookup = None + self.allowBlank = None + self.showInputMsg = None + self.showErrorMsg = None + + self.prompt = None + self.promptTitle = None + self.error = None + self.errorTitle = None + + self.formula1 = None + self.formula2 = None + + def createDOM (self, wb): + nd = node.Element("data-validation") + nd.setAttr("value-type", self.valueType) + nd.setAttr("operator", self.operator) + nd.setAttr("value-list", self.strLookup) + nd.setAttr("allow-blank", self.allowBlank) + nd.setAttr("show-input-message", self.showInputMsg) + nd.setAttr("show-error-message", self.showErrorMsg) + for rng in self.ranges: + s = rng.getName() + elem = nd.appendElement("range") + elem.setAttr("address", s) + + if self.prompt != None: + elem = nd.appendElement("prompt") + elem.setAttr("text", self.prompt) + elem.setAttr("title", self.promptTitle) + + if self.error != None: + elem = nd.appendElement("error") + elem.setAttr("style", self.errorStyle) + elem.setAttr("text", self.error) + elem.setAttr("title", self.errorTitle) + + if self.formula1 != None: + elem = nd.appendElement("formula") + elem.setAttr("index", 1) + elem.setAttr("value", self.formula1) + + if self.formula2 != None: + elem = nd.appendElement("formula") + elem.setAttr("index", 2) + elem.setAttr("value", self.formula2) + + return nd + diff --git a/scratch/mso-dumper/src/xlsrecord.py b/scratch/mso-dumper/src/xlsrecord.py index 9277f642b..dd301817d 100644 --- a/scratch/mso-dumper/src/xlsrecord.py +++ b/scratch/mso-dumper/src/xlsrecord.py @@ -763,9 +763,20 @@ class Dv(BaseRecordHandler): formulaLen = self.readUnsignedInt(2) self.readUnsignedInt(2) # ignore 2 bytes. self.formula1 = self.readBytes(formulaLen) + self.strFormula1 = '' + if len(self.formula1) > 0: + parser = formula.FormulaParser2(self.header, self.formula1) + parser.parse() + self.strFormula1 = parser.getText() + formulaLen = self.readUnsignedInt(2) self.readUnsignedInt(2) # ignore 2 bytes. self.formula2 = self.readBytes(formulaLen) + self.strFormula2 = '' + if len(self.formula2) > 0: + parser = formula.FormulaParser2(self.header, self.formula2) + parser.parse() + self.strFormula2 = parser.getText() rangeCount = self.readUnsignedInt(2) self.ranges = [] @@ -797,24 +808,32 @@ class Dv(BaseRecordHandler): self.appendLine("prompt: %s"%self.prompt) self.appendLine("error: %s"%self.error) self.appendLine("formula 1 (bytes): %s"%globals.getRawBytes(self.formula1, True, False)) - - parser = formula.FormulaParser2(self.header, self.formula1) - parser.parse() - s = parser.getText() - self.appendLine("formula 1 (displayed): %s"%s) + self.appendLine("formula 1 (displayed): %s"%self.strFormula1) self.appendLine("formula 2 (bytes): %s"%globals.getRawBytes(self.formula2, True, False)) - parser = formula.FormulaParser2(self.header, self.formula2) - parser.parse() - s = parser.getText() - self.appendLine("formula 2 (displayed): %s"%s) + self.appendLine("formula 2 (displayed): %s"%self.strFormula2) for rng in self.ranges: self.appendLine("range: %s"%rng.getName()) def fillModel (self, model): self.__parseBytes() - + obj = xlsmodel.DataValidation(self.ranges) + obj.valueType = globals.getValueOrUnknown(Dv.valueTypes, self.valType) + obj.errorStyle = globals.getValueOrUnknown(Dv.errorStyles, self.errStyle) + obj.operator = globals.getValueOrUnknown(Dv.operatorTypes, self.operator) + obj.showInputMsg = self.showInputMsg + obj.showErrorMsg = self.showErrorMsg + obj.strLookup = self.strLookup + obj.allowBlank = self.allowBlank + obj.prompt = self.prompt + obj.promptTitle = self.promptTitle + obj.error = self.error + obj.errorTitle = self.errorTitle + obj.formula1 = self.strFormula1 + obj.formula2 = self.strFormula2 + sheet = model.getCurrentSheet() + sheet.setDataValidation(obj) class DVal(BaseRecordHandler): |