Created
September 8, 2016 17:24
-
-
Save analyticsPierce/ea6fda29971aec0d2920bd1fd70c5345 to your computer and use it in GitHub Desktop.
openpyxl excel export script
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 openpyxl | |
wb = openpyxl.Workbook() | |
wb.guess_types = True | |
sheet = wb.active | |
with open("test_data.csv") as f: | |
reader = csv.reader(f) | |
sheet['D48'].number_format = '#,##0' | |
sheet['M48'].number_format = '($#,##0.00_);[Red]($#,##0.00)' | |
sheet['M49'].number_format = '$#,##0.00' | |
for r, row in enumerate(reader): | |
for c, col in enumerate(row): | |
try: | |
col = float(col) | |
except ValueError: | |
pass | |
sheet.cell(row=r + 1, column=c + 1).value = col | |
wb.save("test_data.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment