第一步:安装Python的xlsxwriter库
pip install xlsxwriter
第二步:导入xlsxwriter库
import xlsxwriter
第三步:向Excel文件中添加多个Sheet
# 创建Excel文件
workbook = xlsxwriter.Workbook('test.xlsx')
# 通过workbook对象创建不同的Sheet,并向每个Sheet中添加数据,相关代码如下
# 向Excel文件中添加Sheet1
worksheet1 = workbook.add worksheet('Sheet1')worksheetl.write('A1','Sheet1-Data')
# 向Excel文件中添加Sheet2
worksheet2 = workbook.add worksheet('Sheet2')worksheet2.write('A1','Sheet2-Data' )
# 关闭Excel文件
workbook.close()
标签:文件,Sheet,python,创建,xlsxwriter,Excel,添加,workbook From: https://www.cnblogs.com/WebLinuxStudy/p/17612427.html