importopenpyxl# Load Excel filewb=openpyxl.load_workbook("Sample.xlsx")# Write new sheetwb.create_sheet("Test")# Save workbook, you can overwrite existing file if you want towb.save("New File.xlsx")
# Write new sheet with Specific Position, 0=first sheetwb.create_sheet("Test",0)
Overwrite specific Cell
# Overwrite data in existing sheetws=wb["Sheet1"]ws["A1"].value="Test"ws.cell(1,2).value="cool book names"
Cell formatting
importopenpyxlfromopenpyxl.stylesimportFont,Colorwb=openpyxl.load_workbook("Sample.xlsx")ws=wb["Sheet1"]# Font stylestyle=Font("Daytona",size=14,color="DC143C",underline="single",strikethrough=True)foriinrange(2,10):ws.cell(i,2).font=stylewb.save("Sample.xlsx")