Fork me on GitHub

Python操作excel文件


 

工具: xlrd, xlwt

安装:pip命令安装即可

使用:

  读 xlrd

import xlrd

book = xlrd.open_workbook(filename)

sheet1 = book.sheet_by_index(0)

for row in range(sheet1.nrows):
    for col in range(sheet1.ncols):
        print(sheet1.cell_value(row, col))

  写 xlwt

import xlwt

wb = xlrd.Workbook()

ws = wb.add_sheet("Sheet1")

ws.write(0,0,"hello")
ws.write(0,1,"world")

wb.save('example.xls')

 

posted @ 2015-11-25 00:40  Roronoa__Zoro  阅读(137)  评论(0编辑  收藏  举报