Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.