Mercurial > hg > ooxml
comparison excel.py @ 70:0003fe7b6b67
beginning work on class structure for excel annotation
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Mon, 26 Jun 2017 18:08:25 +0100 |
parents | |
children | 54bb53434887 |
comparison
equal
deleted
inserted
replaced
69:9e7851375ab7 | 70:0003fe7b6b67 |
---|---|
1 #!/usr/bin/python3 | |
2 '''Class model for analysis of Excel spreadsheets''' | |
3 from jsonweb.encode import to_object, dumper | |
4 try: | |
5 string_types=basestring | |
6 except NameError: | |
7 string_types=str | |
8 | |
9 @to_object(exclude_nulls=True) | |
10 class Book(object): | |
11 def __init__(self,source,sheets=[],formats=[]): | |
12 assert(isinstance(source,string_types)) | |
13 self.source=source | |
14 sheets=list(sheets) | |
15 assert(all(isinstance(s,Sheet) for s in sheets)) | |
16 self.sheets=sheets | |
17 formats=list(formats) | |
18 self.formats=formats | |
19 | |
20 def addSheet(self,sheet): | |
21 assert(isinstance(sheet,Sheet)) | |
22 self.sheets.append(sheet) | |
23 | |
24 @to_object(exclude_nulls=True,suppress=["book"]) | |
25 class Sheet(object): | |
26 def __init__(self,name,book,tables=[],docs=[],misc=[]): | |
27 assert(isinstance(name,string_types)) | |
28 self.name=name | |
29 assert(isinstance(book,Book)) | |
30 self.book=book | |
31 tables=list(tables) | |
32 assert(all(isinstance(s,Region) for s in tables)) | |
33 self.tables=tables | |
34 docs=list(docs) | |
35 assert(all(isinstance(s,Region) for s in docs)) | |
36 self.docs=docs | |
37 misc=list(misc) | |
38 assert(all(isinstance(s,Region) for s in misc)) | |
39 self.misc=misc | |
40 book.addSheet(self) | |
41 | |
42 def addTable(self,table): | |
43 assert(isinstance(table,Region)) | |
44 self.tables.append(table) | |
45 | |
46 @to_object(exclude_nulls=True,suppress=["sheet"]) | |
47 class Region(object): | |
48 def __init__(self,name,sheet=None,ranges=[]): | |
49 if sheet is not None: | |
50 assert(isinstance(sheet,Sheet)) | |
51 self.sheet=sheet | |
52 ranges=list(ranges) | |
53 assert(all(isinstance(s,Range) for s in ranges)) | |
54 self.ranges=ranges | |
55 assert(isinstance(name,string_types)) | |
56 self.name=name | |
57 if sheet is not None: | |
58 sheet.addTable(self) |