Excel文件中有7个sheets, 我原来理解的是,使用这行代码tem_sheet = tem_excel.sheet_by_index(5),可以复制第6个sheet的格式,建立一个新的Excel。
但是每次运行后发现他会把原本的7个sheets完整复制一遍,跟index(5),也就是第6个sheet没啥关系。
然后我把这行代码注释掉,也没什么变化。所以这行代码的作用到底是什么?好像有没有都可以
多谢指教!
# copy an excel file and create a new one
from xlutils.copy import copy
import xlrd
import xlwt
tem_excel = xlrd.open_workbook('/Users/kangyue/python + office/2203.xls', formatting_info=True)
tem_sheet = tem_excel.sheet_by_index(5)
new_excel = copy(tem_excel)
new_sheet = new_excel.get_sheet(1)
new_sheet.write(1, 4, 22)
new_excel.save('new2.xls')