Exemple #1
0
 def process(self, lines, ctx_node, depth=-1):
     count = len(lines)
     container = None
     while lines:
         if depth > -1 and is_empty(lines[0]):
             lines.pop(0)
             break
         match = self.re.match(lines[0])
         if match:
             if match.group(self.BULLET):
                 new_depth = match.end(self.INDENT)
                 if new_depth > depth:
                     if not container:
                         container = ctx_node.append(
                             node.Element(self.container))
                     line = lines.pop(0)[match.end():].rstrip() + " "
                     li = container.append(
                         node.Element(self.item_name, line))
                     self.process(lines, li, new_depth)
                 else:
                     break
             else:
                 line = lines.pop(0)[match.end():].rstrip() + " "
                 ctx_node.append(node.Text(line))
         else:
             break
     ctx_node.normalize()
     return len(lines) < count
Exemple #2
0
 def process(self, lines, ctx_node, depth=-1):
     count = len(lines)
     table = None
     row = None
     td = None
     while lines:
         if row and is_empty(lines[0]):
             lines.pop(0)
             if td: td.normalize()
             row = td = None
             continue
         match = self.re.match(lines[0])
         if match:
             term = match.group(self.TERM)
             if term:
                 if not table:
                     table = ctx_node.append(node.Element("table"))
                 row = table.append(node.Element("tr"))
                 row.append(node.Element("td")).append(
                     node.Element("strong", term))
                 td = row.append(node.Element("td"))
                 text = lines.pop(0)[match.end():].rstrip() + " "
                 if text: td.append(node.Text(text))
             else:
                 if not table: break
                 if not td:
                     row = table.append(node.Element("tr"))
                     row.append(node.Element("td"))
                     td = row.append(node.Element("td"))
                 td.append(node.Text(lines.pop(0).strip() + " "))
         else:
             break
     return len(lines) < count
Exemple #3
0
    def createDOM(self, wb):
        nd = node.Element('worksheet')
        nd.setAttr('version', self.version)

        # cells
        rows = self.__rows.keys()
        rows.sort()
        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(wb)
                rowNode.appendChild(cellNode)
                cellNode.setAttr('col', col)

        # table dimension
        if self.__firstDefinedCell != None:
            nd.setAttr('first-defined-cell', self.__firstDefinedCell.getName())

        if self.__firstFreeCell != None:
            nd.setAttr('first-free-cell', self.__firstFreeCell.getName())

        self.__appendAutoFilterNode(wb, nd)  # autofilter (if exists)
        self.__appendHiddenRowsNode(wb, nd)  # hidden rows
        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
Exemple #4
0
    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
Exemple #5
0
 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
Exemple #6
0
 def process(self, lines, ctx_node):
     count = len(lines)
     if len(lines) > 1 and self.re.match(lines[1]):
         ctx_node.append(
             node.Element(self.name,
                          lines.pop(0).rstrip() + " "))
         lines.pop(0)
     return len(lines) < count
Exemple #7
0
    def createDOM(self, wb):
        nd = node.Element('workbook-global')
        for sb in self.__supbooks:
            if sb.type != Supbook.Type.External:
                continue
            nd.appendChild(sb.createDOM(wb))

        return nd
Exemple #8
0
 def handle(self, text_node, match):
     text_node.split(match.end())
     text = text_node.split(match.start())
     if self.START or self.END: text.value = text.value[self.START:self.END]
     self.unescape(text_node)
     element = node.Element(self.name)
     element.append(text)
     text_node.insert_after(element)
     return element
Exemple #9
0
 def process(self, lines, ctx_node):
     count = len(lines)
     if self.re.match(lines[0]):
         lines.pop(0)
         pre = ctx_node.append(node.Element("pre"))
         while lines:
             if is_empty(lines[0]) or lines[0].startswith((" ", "\t")):
                 pre.append(node.Text(lines.pop(0)))
             else:
                 break
     return len(lines) < count
Exemple #10
0
    def createDOM(self, wb):
        nd = node.Element('formula-cell')
        if self.tokens != None:
            parser = formula.FormulaParser(None, self.tokens)
            parser.parse()
            nd.setAttr('formula', parser.getText())
            s = globals.getRawBytes(self.tokens, True, False)
            nd.setAttr('token-bytes', s)
            if self.cachedResult != None:
                nd.setAttr('formula-result', self.cachedResult)

        return nd
Exemple #11
0
    def createDOM(self, wb):
        nd = node.Element("external-sheet-cache")
        # 1st char is always 0x1.
        nd.setAttr("url", globals.encodeName(self.docURL[1:]))
        for sheet in self.__sheets:
            if sheet[1] == None:
                continue
            elem = sheet[1].createDOM(wb)
            elem.setAttr("name", sheet[0])
            nd.appendChild(elem)

        return nd
Exemple #12
0
 def process(self, lines, ctx_node):
     count = len(lines)
     p = None
     while lines:
         if is_empty(lines[0]):
             lines.pop(0)
             break
         if self.re.match(lines[0]):
             if not p: p = ctx_node.append(node.Element("p"))
             p.append(node.Text(lines.pop(0).rstrip() + " "))
             continue
         break
     return len(lines) < count
Exemple #13
0
 def createDOM(self, wb, filterRange):
     nd = node.Element('arrow')
     col = self.filterID + filterRange.firstCol
     row = filterRange.firstRow
     cell = formula.CellAddress(col, row)
     nd.setAttr('pos', cell.getName())
     nd.setAttr('active', self.isActive)
     eqStr = ''
     if self.equalString1 != None:
         eqStr = self.equalString1
     if self.equalString2 != None:
         eqStr += ',' + self.equalString2
     nd.setAttr('equals', eqStr)
     return nd
Exemple #14
0
    def createDOM(self, wb):
        nd = node.Element('formula-cell')
        if self.tokens != None:
            parser = formula.FormulaParser(None, self.tokens)
            try:
                parser.parse()
                nd.setAttr('formula', parser.getText())
            except:
                if not globals.params.catchExceptions:
                    raise
                pass
            s = globals.getRawBytes(self.tokens, True, False)
            nd.setAttr('token-bytes', s)
            if self.cachedResult != None:
                nd.setAttr('formula-result', self.cachedResult)

        return nd
Exemple #15
0
    def createDOM(self):
        nd = node.Element('workbook')
        nd.setAttr('encrypted', self.encrypted)
        sheets = filter(lambda x: isinstance(x, Worksheet), self.__sheets)
        n = len(sheets)
        if n == 0:
            return nd

        wbglobal = self.getWorkbookGlobal()
        nd.appendChild(wbglobal.createDOM(self))
        for (i, sheet) in enumerate(sheets):
            sheetNode = sheet.createDOM(self)
            nd.appendChild(sheetNode)
            data = wbglobal.getSheetData(i - 1)
            sheetNode.setAttr('name', data.name)
            sheetNode.setAttr('visible', data.visible)

        return nd
Exemple #16
0
    def createDOM(self, wb):
        nd = node.Element("sheet")
        rows = self.__rows.keys()
        rows.sort()
        for row in rows:
            rowElem = nd.appendElement("row")
            rowElem.setAttr("id", row)
            cols = self.__rows[row].keys()
            cols.sort()
            for col in cols:
                cell = self.__rows[row][col]
                celltype, val = cell[0], cell[1]
                cellElem = rowElem.appendElement("cell")
                cellElem.setAttr("col", col)
                cellElem.setAttr("value", val)
                cellElem.setAttr(
                    "type",
                    globals.getValueOrUnknown(ExtSheetCache.cellTypeNames,
                                              celltype))

        return nd
Exemple #17
0
 def process(self, lines, ctx_node):
     count = len(lines)
     match = self.re.match(lines[0])
     if match: ctx_node.append(node.Element("p", lines.pop(0)))
     return len(lines) < count
Exemple #18
0
 def createDOM(self, wb):
     nd = node.Element('sheet')
     return nd
Exemple #19
0
 def createDOM(self, wb):
     nd = node.Element('number-cell')
     nd.setAttr('value', self.value)
     return nd