读取
import xlrd
data = xlrd.open_workbook('D:\qiuwenbin.xls')#打开本地表格
sh = data.sheet_by_index(0)(读取默认的第一个表)
cellName = sh.cell(0,0)#(取sh表中的坐标值)
print(cellName)
写入:
from xlrd import open_workbook
from xlutils.copy import copy
rb = open_workbook('D:\qiuwenbin.xls')
rs = rb.sheet_by_index(0)
wb = copy(rb)
ws = wb.get_sheet(0)
ws.write(0,0,'changed!')
wb.save('D:\qiuwenbin.xls')
创建excel表格
from xlwt import Workbook
book = Workbook(encoding='utf-8')
sheet1 = book.add_sheet('Sheet 1')
sheet1.write(0,0,"我是第一行第一列")
sheet1.write(0,1,"我是第一行第二列")
sheet1.write(1,0,"我是第2行第一列")
sheet1.write(1,1,"我是第2行第二列")
# 保存Excel book.save('path/文件名称.xls')
book.save('D:\\test66666.xls')