Sometimes it's usefull to use MS-Excel as a gui front-end to your data(for viewing and processing),for example while debugging a program. This script makes this task simple.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | from win32com.client import Dispatch
class ExcelTable:
"""
display a data structure in Excel
"""
def __init__(self):
self.xlApp = Dispatch("Excel.Application")
self.xlApp.Visible = 1
self.xlApp.Workbooks.Add()
def Display(self,InputList,StartRow=1,StartColumn=1):
"""
Display a Grid of data in excel
Input list = List of (row,col,value) to describe your data
StartRow,StartColumn - the place where to start to draw you table in excel.
"""
self.List=InputList
for x in self.List:
self.xlApp.ActiveSheet.Cells(x[0]+StartRow,x[1]+StartColumn).Value =str(x[2])
def __del__(self):
self.xlApp.ActiveWorkbook.Close(SaveChanges=0)
self.xlApp.Quit()
del self.xlApp
|
This script supports data as List of tuples of (row,column,value) --> so you need to reformat you data as such. another way is to override the Display method. You can use it to draw a number of tables at different locations.
I choose this interface as simple and generic ways to display data , that simply support adding more complex data types by users.
hopefully you'll find it usefull and interesting