Python,xlsx编写器对excel的写入、公共方法的说明(思维模式图)以及代码示例
支持视频解说地址: Python接口实战17 xlsx写入器写入excel
一、思维导图
。
二、代码示例:
#!/usr/yx DSS /环型手机导入日期时间
导入xlsx写入器
“”一、创建excel文件并创建sheet“”
打开workbook=xlsx writer.workbook (' test.xlsx ' )后,数据将为空
worksheet=workbook.add _ worksheet ('测试' )
'''' 2、将数据写入特定单元格' ' '
#1、文本
worksheet.write('a1 ','巧吧软件测试') )
worksheet.write (1,0,' xlsx ' ) #与A2相同
#1.1、设定行单元格的属性
worksheet.set _ row (0,40 ) )。
#1.2、设定列单元的属性
worksheet.set_column('a:f ',20 ) ) )。
#1.3、自定义格式写入
top=workbook.add _ format (边框:1,'字体大小' :13,'边框' :真,'对齐' 3360 '中心)
worksheet.write('a3 ','巧吧软件测试',top ) )。
# # worksheet.set _ row (0,40,top ) )。
#worksheet.set_column(a:f (,20,顶部) ) ) ) ) ) ) ) ) ) )。
#2、数字
worksheet.write (0,1,32 ) )。
worksheet.write (1,1,35.5 ) )。
#3、函数
worksheet.write (2,1,'=和;c1:c2) )
#4、日期
worksheet.write (0,2,datetime.datetime.strp time (' 2017-11-11 ',' %Y-%m-%d ' ),workbook .添加_ fook
#5、照片
worksheet.insert _ image (0,4,'巧吧软件测试. jpg ' ) ) )。
worksheet.insert _ image (0,3,巧吧软件测试. jpg (,' {'url':'http://www.baidu.com ',' x _ scale ' 33600 )
#6、批量写入列
worksheet.write_column('a22 ',[ 1,2,3,4 ] ) )。
# #批量写入行
worksheet.write_row('a21 ',[ 5,6,7,8 ],顶部) ) ) ) ) ) )。
#7、组合单元格后写入
worksheet.merge_range(4、0、5、2、“巧吧软件测试”,top ) #开始行,开始列,结束行,结束列
使用workbook.close