Last active
March 16, 2017 14:43
-
-
Save hideaki-t/1af95d03989e557056a8f71e4e399087 to your computer and use it in GitHub Desktop.
Revisions
-
hideaki-t revised this gist
Mar 16, 2017 . 2 changed files with 31 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ import zipfile import xml.sax import sys NS = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main' class NonLocalExit(Exception): pass class H(xml.sax.handler.ContentHandler): def startElementNS(self, name, qname, attrs): if name == (NS, 'dimension'): self.ref = attrs.get((None, 'ref')) raise NonLocalExit('found') parser = xml.sax.make_parser() parser.setFeature(xml.sax.handler.feature_namespaces, True) handler = H() parser.setContentHandler(handler) with zipfile.ZipFile(sys.argv[1]) as z: with z.open('xl/worksheets/sheet1.xml') as f: try: parser.parse(f) except NonLocalExit: pass print(handler.ref) -
hideaki-t created this gist
Mar 16, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import zipfile import xml.sax import sys class H(xml.sax.handler.ContentHandler): def startElementNS(self, name, qname, attrs): if name[1] == 'dimension': print(name, attrs.get('ref')) parser = xml.sax.make_parser() parser.setFeature(xml.sax.handler.feature_namespaces, True) parser.setContentHandler(H()) with zipfile.ZipFile(sys.argv[1]) as z: with z.open('xl/worksheets/sheet1.xml') as f: parser.parse(f)