打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Python 读写 Excel

Python 读写 Excel

python excel格式:http://blog.sina.com.cn/s/blog_5357c0af01019gjo.html
基本上, 这个网页已经说明一切了: http://pypi.python.org/pypi/xlrd

等有时间再把这个页面写漂亮,现在先记一些代码.

读Excel

先建个simple.xls

from xlrd import open_workbook

wb = open_workbook('simple.xls','rb')
for s in wb.sheets():
    print 'Sheet:',s.name
    for row in range(s.nrows):
        values=[]
        for col in range(s.ncols):
            values.append(s.cell(row,col).value)
        print ",".join(values)
    print

        


写Excel

from tempfile import TemporaryFile
from xlwt import Workbook

book = Workbook()
sheet1 = book.add_sheet('Sheet 1')
book.add_sheet('Sheet 2')
sheet1.write(0,0,'A1')
sheet1.write(0,1,'B1')

row1 = sheet1.row(1)
row1.write(0,'A2')
row1.write(1,'B2')

sheet1.col(0).width = 10000

sheet2 = book.get_sheet(1)
sheet2.row(0).write(0,'Sheet 2 A1')
sheet2.row(0).write(1,'Sheet 2 B1')
sheet2.flush_row_data()

sheet2.write(1,0,'Sheet 2 A3')
sheet2.col(0).width = 5000
sheet2.col(0).hidden = True

book.save('simple2.xls')
book.save(TemporaryFile())

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
python 3 操作 excel
python读写excel文件
操作excel的xlwt库难道没有删除sheet 的方法吗?
利用jxl.jar包操作excel
(ok)python3 如何将txt与excel 进行相互转换(.xls、.xlsx)
Python提取多张excel表上的数据,合并汇总到一张新表
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服