python (xlrd, xlwt, xlutils实现读写excel,xls,xlsx)

1 xlrd对表格进行读操作,只能进行读取,无法进行更改
对表格进行读操作,只能进行读取,无法进行更改

import xlrd
rb = xlrd.open_workbook('1.xls')
sheet1 = rb.sheet_by_index(0)
rows = sheet1.nrows #获取行数
cols = sheet1.ncols #获取列数
names = data.sheet_names()    #返回book中所有工作表的名字
value = sheet1.cell()

2 xlwt只能对表格进行写操作,无法读取

import xlwt
wookbook = xlwt.Wookbook(encoding='utf-8')
sheet = wookbook.add_sheet('1')
sheet.write(row, col, value)
wookbook.save('3.xls')

3 xlutils能对表格进行读写操作
import xlrd
from xlutils.copy import copy
rb = xlrd.open_wookbook(‘1xls’)#读表格1
sheet = rb.sheets(0)
wr = copy(rb)
ws = wb.get_sheet(0)#写操作表格1
ws.write(row, col, value)
wr.save('1.xls)

你可能感兴趣的:(python)