write excel with python xlwt

write excel with python xlwt

1. install

pip install xlwt

2. xlwt.Workbook Object

他有2个经常使用的方法,一个就是save 方法来保存的,另一个就是add_sheet 加入工作表。
1. save
2. add_sheet

3. Worksheets Object

是由Workbook这个对象创建出来的。能够直接write写cell 。

也能够返回Rows 这个类,然后由Rows 来write cell。

4. 3种写cell的方式:

  1. Worksheet.write(row_index,column_index,value)
  2. Row.write(column_index,value)
  3. Specialist write methods on the Row class

5. 直接用write的方法的实例

写个99乘法表:

import xlwt

wb = xlwt.Workbook()
ws = wb.add_sheet('sheet1')
ws2 = wb.add_sheet('sheet2')

def write99():
        for i in range(1,10):
                for j in range(1,10):
                        ws.write(i-1,j-1,i*j)

write99()
wb.save('aca.xls')

參考文档

http://xlwt.readthedocs.org/en/latest/

posted on 2017-08-02 15:10  ljbguanli  阅读(254)  评论(0编辑  收藏  举报