标签:默认 xls 步骤 port 导入 close row 行高 操作
这里主要是介绍Excel的以下操作:新建工作表、在表格里写数据、合并单元格、设置行高、列宽等操作。其一般的操作步骤如下:
一、导入模块:import xlsxwriter
二、创建workbook对象:workbook = xlsxwriter.Workbook(文件名)
三、创建工作表对象:worksheet = workbook.add_worksheet(<表名>) # 表名省略时就默认为sheet1
四、对工作表的相关操作
五、关闭并保存workbook:workbook.close()
例子如下:
import xlsxwriter # 创建工作表 workbook = xlsxwriter.Workbook(‘test.xlsx‘) # 默认创建sheet1 worksheet = workbook.add_worksheet() # 创建sheet2 worksheet = workbook.add_worksheet(‘sheet2‘) workbook.close()
import xlsxwriter workbook = xlsxwriter.Workbook(‘test.xlsx‘) worksheet = workbook.add_worksheet() worksheet.write(0, 0, ‘你好‘) # 行号和列标均是从0开始 workbook.close()
import xlsxwriter workbook = xlsxwriter.Workbook(‘test.xlsx‘) worksheet = workbook.add_worksheet() worksheet.merge_range(‘A1:H1‘, ‘合并单元格‘) workbook.close()
import xlsxwriter workbook = xlsxwriter.Workbook(‘test.xlsx‘) worksheet = workbook.add_worksheet() worksheet.set_row(0, 70) workbook.close()
标签:默认 xls 步骤 port 导入 close row 行高 操作
原文地址:https://www.cnblogs.com/Treelight/p/12818408.html