xlrd+xlwt读写Excel
读取
import xlrd
xlsx = xlrd.open_workbook(filename)
sheet = xlsx.sheet_by_name(sheetname)
sheet = xlsx.sheet_by_index(sheetindex)
sheet.table.cell_value(row,column)
sheet.table.cell(row,column).value
sheet.table.row(rownum)[column].value
写入
import xlwt
xlsx = xlrt.Workbook()
sheet = xlsx.add_sheet(sheetname)
text = sheet.write(row,column,"text")
new_workbook.save(filedir)
复制格式
from xlutils.copy import copy
import xlrd
import xlwt
style = xlwt.XFStyle()
##字体
font = xlwt.Font()
font.name = "微软雅黑"
font.bold = True
font.height = 18*20
style.font = font
##边框
borders = xlwt.Borders()
borders.top = xlwt.Borders.THIN
borders.bottom = xlwt.Borders.THIN
borders.left = xlwt.Borders.THIN
borders.right = xlwt.Borders.THIN
style.borders = borders
##对齐
alignment = xlwt.Alignment()
alignment.herz = xlwt.Alignment.HERZ_CENTER
alignment.verz = xlwt.Alignment.VERZ_CENTER
style.alignment = alignment
网友评论