Skip to content

Instantly share code, notes, and snippets.

@analyticsPierce
Created September 8, 2016 17:24
Show Gist options
  • Save analyticsPierce/ea6fda29971aec0d2920bd1fd70c5345 to your computer and use it in GitHub Desktop.
Save analyticsPierce/ea6fda29971aec0d2920bd1fd70c5345 to your computer and use it in GitHub Desktop.
openpyxl excel export script
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