changeset 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 9e7851375ab7
children 54bb53434887
files excel.py
diffstat 1 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/excel.py	Mon Jun 26 18:08:25 2017 +0100
@@ -0,0 +1,58 @@
+#!/usr/bin/python3
+'''Class model for analysis of Excel spreadsheets'''
+from jsonweb.encode import to_object, dumper
+try:
+  string_types=basestring
+except NameError:
+  string_types=str
+
+@to_object(exclude_nulls=True)
+class Book(object):
+  def __init__(self,source,sheets=[],formats=[]):
+    assert(isinstance(source,string_types))
+    self.source=source
+    sheets=list(sheets)
+    assert(all(isinstance(s,Sheet) for s in sheets))
+    self.sheets=sheets
+    formats=list(formats)
+    self.formats=formats
+
+  def addSheet(self,sheet):
+    assert(isinstance(sheet,Sheet))
+    self.sheets.append(sheet)
+
+@to_object(exclude_nulls=True,suppress=["book"])
+class Sheet(object):
+  def __init__(self,name,book,tables=[],docs=[],misc=[]):
+    assert(isinstance(name,string_types))
+    self.name=name
+    assert(isinstance(book,Book))
+    self.book=book
+    tables=list(tables)
+    assert(all(isinstance(s,Region) for s in tables))
+    self.tables=tables
+    docs=list(docs)
+    assert(all(isinstance(s,Region) for s in docs))
+    self.docs=docs
+    misc=list(misc)
+    assert(all(isinstance(s,Region) for s in misc))
+    self.misc=misc
+    book.addSheet(self)
+
+  def addTable(self,table):
+    assert(isinstance(table,Region))
+    self.tables.append(table)
+
+@to_object(exclude_nulls=True,suppress=["sheet"])
+class Region(object):
+  def __init__(self,name,sheet=None,ranges=[]):
+    if sheet is not None:
+      assert(isinstance(sheet,Sheet))
+    self.sheet=sheet
+    ranges=list(ranges)
+    assert(all(isinstance(s,Range) for s in ranges))
+    self.ranges=ranges
+    assert(isinstance(name,string_types))
+    self.name=name
+    if sheet is not None:
+      sheet.addTable(self)