已存在的excel某一column,row,index是第几个sheet进行内容修改
def writetoExcel(index,column,修改内容):
PATH = 路径 + name.xlsx
rb =xlrd.open_workbook(PATH )
wb = copy(rb)
s=wb.get_sheet(index)
s.write(column+1,row+1,修改内容)#row行号,列号column
wb.save(PATH)
代码:
#进行excel字体大小进行修改
#coding:utf-8
import xlwt;
import xlrd;
from xlutils.copy import copy;
data = xlrd.open_workbook(r'D:Letter7.xls',formatting_info=True) #formatting_info复制单元格格式
w = copy(data)
for i in range(len(data.sheet_names())):
sheet1 = data.sheet_by_index(i)
sheet_data = sheet1.cell(8, 8).value #(行号-1,列号-1).value取单元格内容
data_li = sheet_data.split('_')
item = data_li.pop(-1)
data_li.insert(0, item)
print(data_li)
data_str = '_'.join(data_li)
print(data_str)
style = xlwt.XFStyle()
font = xlwt.Font()
font.height = 0x00dc #220:字体大小*20后转16进制
font.name = '宋体'
style.font = font
w.get_sheet(i).write(8,8,data_str,style)
w.save('D:Letter8.xls')