Last active
August 29, 2015 14:26
-
-
Save edgabaldi/b10982036283980832f0 to your computer and use it in GitHub Desktop.
easy way to write xls files with a dict/tuple
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 characters
| * easy way to set style of a sheet | |
| * totalization ? | |
| * Use more that one "table" by sheet. | |
| - Maybe use cursors. (self.cursor_row, self.cursor_line) |
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 characters
| header = ('id', 'product', 'unitme', 'average_proce',) | |
| body = [{ | |
| 'id': 10, | |
| 'product': 'foo', | |
| 'unitme': 'un', | |
| 'average_price': Decimal('15.0') | |
| }] | |
| import xlwt | |
| class SpreadSheet(object): | |
| def __init__(self, header, content): | |
| self.header = header | |
| self.content = content | |
| self.workbook = xlwt.Workbook(encoding='UTF-8') | |
| self.sheet_list = [] | |
| def add_sheet(self, name): | |
| if name in self.sheet_list.keys(): | |
| raise Exception('Sheet with this name already exists.') | |
| self.sheet_list[name] = self.workbook.add_sheet(name) | |
| def get_sheet(self, name): | |
| return 'name' in self.sheet_list.keys() and self.sheet_list[name] | |
| def set_content(self, sheet, header, body): | |
| for line, data in enumerate(body): | |
| for row, order in enumerate(header): | |
| sheet.write(line, row, data[order]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment