Skip to content

Commit fe9ecff

Browse files
committed
add new remove sheets example
1 parent db486d2 commit fe9ecff

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

chapter38_excel/remove_sheets.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# remove_sheets.py
2+
3+
import openpyxl
4+
5+
def create_worksheets(path):
6+
workbook = openpyxl.Workbook()
7+
sheet1 = workbook.create_sheet()
8+
# Insert a worksheet
9+
workbook.create_sheet(index=1,
10+
title='Second sheet')
11+
print(workbook.sheetnames)
12+
workbook.remove(workbook['Second sheet'])
13+
print(workbook.sheetnames)
14+
workbook.save(path)
15+
16+
if __name__ == '__main__':
17+
create_worksheets('remove_sheets.xlsx')

0 commit comments

Comments
 (0)