Created
May 7, 2019 06:02
-
-
Save DataSolveProblems/c54ea3287e37172705b34346c32d08f0 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
| import xlsxwriter as xw | |
| wbFormatTable = xw.Workbook('Format Table.xlsx') | |
| wsTransaction = wbFormatTable.add_worksheet('Transactions') | |
| transactions = ( | |
| ['5/1/2019', 'Buy', 100.00], | |
| ['5/2/2019', 'Sell', 200.00], | |
| ['5/3/2019', 'Buy', 300.00], | |
| ['5/4/2019', 'Sell', 400.00], | |
| ['5/5/2019', 'Sell', 500.00], | |
| ) | |
| formatCategory = wbFormatTable.add_format(dict(bold=True, italic=True)) | |
| currency = wbFormatTable.add_format(dict(num_format='$#,##0.00')) | |
| # Insert Header' | |
| wsTransaction.write(0, 0, 'Tran Date') | |
| wsTransaction.write(0, 1, 'Tran Type') | |
| wsTransaction.write(0, 2, 'Tran Amount') | |
| row_number = 1 | |
| col_number = 0 | |
| for tranDate, tranType, tranAmt in transactions: | |
| wsTransaction.write(row_number, col_number, tranDate) | |
| wsTransaction.write(row_number, col_number + 1, tranType, formatCategory) | |
| wsTransaction.write(row_number, col_number + 2, tranAmt, currency) | |
| row_number += 1 | |
| wsTransaction.write(row_number, 1, 'Total Amonut', bold) | |
| wsTransaction.write(row_number, 2, "=SUM(C2:C" + str(row_number) + ')', currency) | |
| wbFormatTable.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment