码迷,mamicode.com
首页 > 编程语言 > 详细

Python操作excel文件

时间:2015-11-25 01:09:52      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:


 

工具: 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)

 

Python操作excel文件

标签:

原文地址:http://www.cnblogs.com/roronoa-sqd/p/4993440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!