创建工作表对象
work_book = xlsxwriter.Workbook('my first.xlsx') # 创建一个excel文件,文件名为"my first.xlsx"
为工作表添加sheet对象
如果不指定文件名,默认名字为sheet + 当前sheet的数量
work_sheet1 = work_book.add_worksheet() # 添加shhet1 work_sheet2 = work_book.add_worksheet('my excel.xlsx') # 添加sheet名字为my excel.xlsx work_sheet3 = work_book.add_worksheet() # 不加参数,默认添加sheet3
worksheet类
- write_number:写入数字
- write_blank:写入空格
- write_formula:写入公式
- write_datetime:写入时间格式
- write_boolean:写入逻辑数据
- write_url:写入链接地址
work_sheet2.write_string(0, 0, 'this is write string!') work_sheet2.write_number('A2', 123456) work_sheet2.write_blank('A3', None) work_sheet2.write_number('B1', 12) work_sheet2.write_number('B2', 24) work_sheet2.write_number('B3', 35) work_sheet2.write_formula('B7', '=sum(b1:b5)') work_sheet2.write_datetime(0, 3, datetime.datetime.strptime('2019-04-18', '%Y-%m-%d'), work_book.add_format({'num_format': 'yyyy-mm-dd'}))
work_sheet1.write_boolean(0, 0, True)
work_sheet1.write_url('A2', 'http://www.baidu.com')