CalcParser

From Apache OpenOffice Wiki
Revision as of 18:34, 29 March 2007 by Jza (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

I'll document this later, so far the code is the following:

[python]

  1. !/bin/env python

import sys from xml.sax import saxutils from xml.sax import parse from xml.sax import handler # Python 2.3 uses the handler

  1. Replace DefaultHandler with ContentHandler
  2. from the handler modules

class CalcHandler(handler.ContentHandler):

   def __init__(self):
       self.chars=[]
       self.cells=[]
       self.rows=[]
       
   def characters(self, content):
       self.chars.append(content)
   def startElement(self, name, atts):
       if name=="table:table-cell":
           self.chars=[]
       elif name=="table:table-row":
           self.cells=[]
   
   def endElement(self, name):

if name=="table:table-cell":

           self.cells.append(.join(self.chars))
       elif name=="table:table-row":
           self.rows.append(self.cells)

calcHandler=CalcHandler() parse(sys.argv[1], calcHandler) print calcHandler.rows

Personal tools