Excel读取模块 xlrd
import xlrd
data = xlrd.open_workbook("data1.xlsx")
print(data.sheets())
print(data.sheet_load(0)
print(data.sheet_by_name())
print(data.sheet_by_index())
print(data.sheet_names())
print(data.nsheets)
sheet = data.sheet_by_index(0)
print(sheet.nrows)
print(sheet.row(1))
print(sheet.row(1)[2].value)
print(sheet.row_types(1))
print(sheet.row_values(1))
print(sheet.row_len(1))
sheet = data.sheet_by_index(0)
print(sheet.ncols)
print(sheet.col(1))
print(sheet.col(1)[2].value)
print(sheet.col_types(1))
print(sheet.col_values(1))
print(sheet.col_len(1))
sheet = data.sheet_by_index(0)
print(sheet.cell(1,2))
print(sheet.cell_type(1,2))
print(sheet.cell(1,2).ctype)
print(sheet.cell(1,2).value)
print(sheet.cell_value(1,2))
Extcel写入模块 xlwt
import xlwt
titlestyle = xlwt.XFStyle()
titlefont = xlwt.Font()
titlefont.name = "宋体"
titlefont.bold = True
titlefont.height = 11*20
titlefont.colour_index = 0x08
titlestyle.font = titlefont
cellalign = xlwt.Alignment()
cellalign.horz = 0x02
cellalign.wert = 0x02
titlestyle.alignment = cellalign
wb = xlmt.Workbook()
ws = wb.add_sheet('CNY')
ws.write_merge(0,1,0,5,'2019', titlestyle)
wb.save("2019-CNY.xls")
data = (("aaa", 10, 20, 50),("bbb", 30, 20, 10))
for i, item in enumerate(data):
for j, val in enumerate(item):
ws.write(i+2, j, val)