python编写Excel表格

安装xlsxwriter,全局命令pip install xlsxwriter。
先写简易方法,封装简易类以后再补充。处理表格格式后期补充

def write_Excel():
    workbook=xlsxwriter.Workbook('write.xlsx')#在同一目录简历文件
    worksheet=workbook.add_worksheet('new_sheet')#建表
    worksheet.write('A1','A')
    worksheet.write('B1','B')
    worksheet.write('C1','C')
    for i in range(1,10):#用循环多次输入类容
        i=str(i)
        try:
            forexcel(worksheet,i,'excelmessage')
        except:
            forexcel(worksheet,i,'excelmessage')
        finally:
            pass
    workbook.close()
def forexcel(worksheet,i,excelmessage):
	j=str(int(i)+1)
    worksheet.write('A'+j,'A'+excelmessage+i)
    worksheet.write('B'+j,'B'+excelmessage+i)
    worksheet.write('C'+j,'C'+excelmessage+i)
if __name__ == '__main__':
    located()

你可能感兴趣的:(测试)