python 生成excel
2013-04-20 11:33
239 查看
需要用到openpyxl这跟模块
安装
使用方法
参考资料
api http://pythonhosted.org/openpyxl/api.html
openpyxl 读写excel2007使用笔记
安装
easy_install openpyxl
使用方法
from openpyxl.workbook import Workbook from openpyxl.writer.excel import ExcelWriter from openpyxl.cell import get_column_letter from openpyxl.style import Color, Fill from openpyxl.cell import Cell #新建一个workbook wb = Workbook() #第一个sheet是ws ws = 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 ##背景 好像不太好用 是个BUG ws.cell('A2').style.fill.fill_type =Fill.FILL_SOLID ws.cell('A2').style.fill.start_color.index =Color.DARKRED ##修改某一列宽度 ws.column_dimensions["C"].width =60.0 ##增加一个表 ws = wb.create_sheet() ws.title = u'结单统计' ##保存生成xml file_name = 'test.xlsx' file_dir = '/home/x/' dest_filename = '%s%s'%(file_dir,file_name) ew = ExcelWriter(workbook = wb) ew = ExcelWriter(workbook = wb)
参考资料
api http://pythonhosted.org/openpyxl/api.html
openpyxl 读写excel2007使用笔记
相关文章推荐
- 服务器巡检shell脚本,python生成excel文档并邮件发出
- python脚本――生成EXCEL,连接数据库,并将指定数据写入EXCEL
- python 读取excel 生成json 读取json
- 基于python实现在excel中读取与生成随机数写入excel中
- Python实现导出数据生成excel报表的方法示例
- php中使用python生成excel报表
- 转载:使用Python一键生成Oracle性能excel曲线图
- python实现kubernetes生成Excel报表并且Email
- 使用python生成excel格式的图片
- python结合Arcpy处理EXCEL数据生成多边形
- python读取和生成excel文件
- Python MySQLdb 查询生成 Excel 文件
- python读取excel文件生成sql文件
- Python中生成(写入数据到)Excel文件
- Python读取excel指定列生成指定sql脚本
- python 生成 ppt word outmail excel
- python 按固定格式数据生成excel报表源代码
- Python将Excel生成SHP
- python前端生成excel
- 【python】 python 查询oracle数据生成excel