python写入excel表格(xls,xlsx等)

写excel表要用到xlwt模块,官网下载(http://pypi.python.org/pypi/xlwt)

1、导入模块

  import xlwt

2、创建workbook(其实就是excel,后来保存一下就行)

  workbook = xlwt.Workbook(encoding = 'ascii')

3、创建表
  worksheet = workbook.add_sheet('My Worksheet')

4、往单元格内写入内容

  worksheet.write(0, 0, label = 'Row 0, Column 0 Value')

5、保存

  workbook.save('Excel_Workbook.xls')

write函数具体使用方法:

worksheet.write(0, 0, 'Hello')          # write_string()
worksheet.write(1, 0, 'World')          # write_string()
worksheet.write(2, 0, 2)                # write_number()
worksheet.write(3, 0, 3.00001)          # write_number()
worksheet.write(4, 0, '=SIN(PI()/4)')   # write_formula()
worksheet.write(5, 0, '')               # write_blank()
worksheet.write(6, 0, None)             # write_blank()

参考:

https://blog.csdn.net/auserbb/article/details/79267799

https://www.cnblogs.com/MrLJC/p/3715783.html

猜你喜欢

转载自blog.csdn.net/qq_21997625/article/details/89453614