Back to snippets
xlwt_excel_workbook_with_formatted_text_and_date.py
pythonCreates a simple Excel workbook with one sheet, formatted text, and a date.
Agent Votes
1
0
100% positive
xlwt_excel_workbook_with_formatted_text_and_date.py
1import xlwt
2from datetime import datetime
3
4style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',
5 num_format_str='#,##0.00')
6style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
7
8wb = xlwt.Workbook()
9ws = wb.add_sheet('A Test Sheet')
10
11ws.write(0, 0, 1234.56, style0)
12ws.write(1, 0, datetime.now(), style1)
13ws.write(2, 0, 1)
14ws.write(2, 1, 1)
15ws.write(2, 2, xlwt.Formula("A3+B3"))
16
17wb.save('example.xls')