MCPcopy Create free account
hub / github.com/ActiveState/code / ExcelHandler

Class ExcelHandler

recipes/Python/192914_Parsing_Excel_XML/recipe-192914.py:5–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3from xml.sax import parse
4
5class ExcelHandler(saxutils.DefaultHandler):
6 def __init__(self):
7 self.chars=[]
8 self.cells=[]
9 self.rows=[]
10 self.tables=[]
11
12 def characters(self, content):
13 self.chars.append(content)
14
15 def startElement(self, name, atts):
16 if name=="Cell":
17 self.chars=[]
18 elif name=="Row":
19 self.cells=[]
20 elif name=="Table":
21 self.rows=[]
22
23 def endElement(self, name):
24 if name=="Cell":
25 self.cells.append(''.join(self.chars))
26 elif name=="Row":
27 self.rows.append(self.cells)
28 elif name=="Table":
29 self.tables.append(self.rows)
30
31excelHandler=ExcelHandler()
32parse(sys.argv[1], excelHandler)

Callers 1

recipe-192914.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected