Skip to content

Instantly share code, notes, and snippets.

@patmandenver
Created January 16, 2020 21:43
Show Gist options
  • Save patmandenver/23aef1096b40ad05d37a909d4065a7cc to your computer and use it in GitHub Desktop.
Save patmandenver/23aef1096b40ad05d37a909d4065a7cc to your computer and use it in GitHub Desktop.
Simple example using openpyxl that create two worksheets
#!/usr/bin/env python3
import openpyxl
from openpyxl import Workbook
#############################################
# MAIN
#############################################
if __name__ == '__main__':
wb = Workbook()
# grab the active worksheet
ws_01 = wb.active
#Set the title of the worksheet
ws_01.title = "First Sheet"
#place a few values in
ws_01['A1'] = 1
ws_01['B2'] = 2
ws_01['C3'] = 3
ws_02 = wb.create_sheet()
ws_02.title = "Second Sheet"
for row in range (1, 6):
for col in range (1, 4):
value = row*col
ws_02.cell(row, col, value)
#Save it in an Excel fie
wb.save("test_02.xlsx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment