Python 读写 Excel(转)

时间:2023-03-09 06:22:39
Python 读写 Excel(转)

Python 读写 Excel

基本上, 这个网页已经说明一切了: 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

sheet2.col(0).hidden = True

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