python通过openpyxl生成Excel文件,pythonopenpyxl,from openpyx
文章由Byrx.net分享于2019-03-23 09:03:58
python通过openpyxl生成Excel文件,pythonopenpyxl,from openpyx
from openpyxl.workbook import Workbookfrom openpyxl.writer.excel import ExcelWriterfrom openpyxl.cell import get_column_letterfrom openpyxl.style import Color, Fillfrom openpyxl.cell import Cell#新建一个workbookwb = Workbook()#第一个sheet是wsws = wb.worksheets[0]#设置ws的名称ws.title = u"下单统计"#给A1赋值ws.cell('A1').value = '%s'%("跟随总数")#给A2赋值#先把数字转换成字母col = get_column_letter(1)#赋值ws.cell('%s%s'%(col, 2)).value = '%s' % ("A2“) #字体修改样式##颜色ws.cell('A2').style.font.color.index =Color.GREEN##字体名称ws.cell('A2').style.font.name ='Arial'##字号ws.cell('A2').style.font.size =8##加粗ws.cell('A2').style.font.bold =True##不知道干啥用的ws.cell('A2').style.alignment.wrap_text =True##背景 好像不太好用 是个BUGws.cell('A2').style.fill.fill_type =Fill.FILL_SOLIDws.cell('A2').style.fill.start_color.index =Color.DARKRED##修改某一列宽度ws.column_dimensions["C"].width =60.0##增加一个表ws = wb.create_sheet()ws.title = u'结单统计'##保存生成xmlfile_name = 'test.xlsx'file_dir = '/home/x/'dest_filename = '%s%s'%(file_dir,file_name)ew = ExcelWriter(workbook = wb)ew = ExcelWriter(workbook = wb)
评论关闭