Created
May 7, 2019 06:02
-
-
Save DataSolveProblems/b0d4f475249af41b40036ba9584071b0 to your computer and use it in GitHub Desktop.
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
| from datetime import datetime | |
| import xlsxwriter as xw | |
| expenses = ( | |
| ['Rent', '2019-05-01', 1500], | |
| ['Gas', '2019-05-15', 20.50], | |
| ['Grocery', '2019-05-16', 100], | |
| ['Phone Bill', '2019-05-21', 59.99], | |
| ) | |
| wb = xw.Workbook('Expenses2.xlsx') | |
| ws = wb.add_worksheet('Expenses') | |
| column_width = ws.set_column(1, 1, 25) | |
| row_number = 1 | |
| col_number = 0 | |
| date_format = wb.add_format(dict(num_format='mmmm d yyyy')) | |
| money_format = wb.add_format(dict(num_format='$#,##0.00')) | |
| bold = wb.add_format(dict(bold=True)) | |
| ws.write('A1', 'Category', bold) | |
| ws.write('B1', 'Date', bold) | |
| ws.write('C1', 'Amount', bold) | |
| for category, date_str, amount in expenses: | |
| # convert the date string into a datetime object | |
| date = datetime.strptime(date_str, '%Y-%m-%d') | |
| ws.write(row_number, col_number, category) | |
| ws.write(row_number, col_number + 1, date, date_format) | |
| ws.write(row_number, col_number + 2, amount, money_format) | |
| row_number +=1 | |
| wb.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment