-
Notifications
You must be signed in to change notification settings - Fork 0
Methods
Martin Davtyan edited this page Jun 6, 2015
·
11 revisions
Algorithms working with Excel data are going to be implemented as methods of the Context object. This object is loaded into the memory throughout the entire lifetime of Worker. Data written by one method should be accessible to other methods.
_______ events _________
| | -----> | Worker |
| Excel | |(runtime)|
|_______| <----- |_________|
actions
| What we need to do | What needs to be stored |
|---|---|
| Header detection | Position of header, column names on every sheet |
| Table detection | Position of beginning and end of table on every sheet |
| Error detection for columns | Column validation features (numpy.array's) |
| Autofill from another column (in another sheet) | A sequence of previously entered cells with their position |
| Selecting elements that user highlights | A sequence of previously highlighted elements |
| Event name | Triggered when | Information contained (passed to Worker) |
|---|---|---|
| WorkbookOpen | New Excel file is open | Name of file |
| WorkbookBeforeClose | Before the Excel file is closed | Name of file |
| SheetChange | Any cell is changed | A new value of a cell, it's metaparameters (formatting, etc, could serialize Excel Cell object into a dict) and a cell address |
| UndoComnsenseChange | User presses Undo after comnsense changed something | ComnsenseActionID to be cancelled |
| RangeResponse | Range requested by the worker is retrieved | List of lists of values. Sublists are rows, lists are columns, see PyWin32 below. |
| Action name | Description | Information contained (passed to Excel) |
|---|---|---|
| ComnsenseChange | Change the sheet based on comnsense inference (color cell red, autofill, etc.) | Range address and range values in Python format |
| RangeRequest | Request values for an Excel range (A1:A10, C3:D4, etc, see Range object | Range |
For the sake of debugging and consistency, it's best to keep Python excel manipulation API consistent with PyWin32. Examples (motivated by tutorial):
>>> import win32com.client
>>> import win32com.client as win32
>>> excel = win32.gencache.EnsureDispatch('Excel.Application')
>>> excel.Visible = True
>>> ws = wb.Worksheets[1]
>>> ws
<win32com.gen_py.Microsoft Excel 14.0 Object Library._Worksheet instance at 0x43791624>
>>> ws.Range("A5:D5").Value = [2,3,4,66]
>>> ws.Range("H1:H3").Value = [[12],[15],[66]]
>>> ws.Range("A1:B2").Value
((2.0, 3.0), (2.0, 3.0))