python使用python-docx导出word
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
'''
from docx import Document
from docx.shared import Inches class Record(object):
def __init__(self):
self.recordset=[] class OutDocx(object):
def __init__(self):
self.recordset=[
{'id':1,'qty':'test1','desc':'描述1'},
{'id':2,'qty':'test2','desc':'描述2'},
{'id':3,'qty':'test3','desc':'描述3'}] def get_docx(self):
document = Document()
document.add_heading('Document Title', 0)
p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True document.add_heading('Heading, level 1', level=1)
document.add_paragraph('Intense quote', style='Intense Quote') document.add_paragraph('first item in unordered list', style='List Bullet')
document.add_paragraph('first item in ordered list', style='List Number') document.add_picture('monty-truth.png', width=Inches(1.25)) table = document.add_table(rows=1,cols=3)
table.style = 'TableGrid'
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
hdr_cells[1].text = 'Id'
hdr_cells[2].text = 'Desc' for item in self.recordset:
row_cells = table.add_row().cells
row_cells[0].text = str(item['qty'])
row_cells[1].text = str(item['id'])
row_cells[2].text = item['desc'] document.add_page_break() document.save('demo.docx') if __name__ == '__main__':
test = OutDocx()
test.get_docx()
python使用python-docx导出word的更多相关文章
- 【c#搬砖记】用Docx导出word格式的docx文件
DocX开源网址:http://docx.codeplex.com/ 1.引入DocX.dll 调用ReplaceText()方法替换模板中的字符.只支持docx格式的word文档 using (Do ...
- C#通过模板导出Word的两种方法(超简单)
方法一:使用Office的组件 使用该方法必须要安装Office 1.制作Word模板 在需要填充内容的地方增加标识符号,方便之后替换使用,例如 [项目名称],其中[]符号和中间的文字可根据个人情况进 ...
- Python 使用 win32com 模块对 word 文件进行操作
what's the win32com 模块 win32com 模块主要为 Python 提供调用 windows 底层组件对 word .Excel.PPT 等进行操作的功能,只能在 Windows ...
- 太方便了!利用Python对批量Pdf转Word
在wps或者office里面可以将pdf转word,不过只能免费转前面5页,超过5页就需要会员.今天教大家一个Python办公小技巧:批量Pdf转Word ,这样可以自由想转多少页都可以. 思路:这里 ...
- 用Python编写博客导出工具
用Python编写博客导出工具 罗朝辉 (http://kesalin.github.io/) CC 许可,转载请注明出处 写在前面的话 我在 github 上用 octopress 搭建了个人博 ...
- C#导出Word文档开源组件DocX
1.帮助文档,这东西找了很久,而且它版本很旧,还是英文,W8.1系统上打不开 http://download.csdn.net/detail/zuofangyouyuan/7673573 2.开源网址 ...
- python打造漏洞数据导出工具
功能 [x] 支持导出的数据:IP地址.漏洞名称.风险等级.整改建议.漏洞描述.漏洞CVE编号.漏洞对应端口.漏洞对应协议.漏洞对应服务等. [x] 导出不同端口的同一个漏洞,也就是一个端口对应一个漏 ...
- python生成requirements.txt 导出项目依赖
使用pip freeze $ pip freeze > requirements.txt 这种方式是把整个环境中的包都列出来了,如果是虚拟环境可以使用. 通常情况下我们只需要导出当前项目的req ...
- python将字典列表导出为Excel文件的方法
将如下的字典列表内容导出为Excel表格文件形式: 关于上图字典列表的写入,请参考文章:https://blog.csdn.net/weixin_39082390/article/details/ ...
- poi导出word文档,doc和docx
maven <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --><dependency> <gro ...
随机推荐
- Eclipse设置Tab键缩进4个空格的步骤,也就是按一下Tab键输出四个空格
Eclipse设置Tab键缩进4个空格的步骤,也就是按1下Tab键输出4个空格,步奏如下 1.点击 window->preference-,选择 General->Editors-> ...
- 混合开发Js bridge新秀-DSBridge iOS篇
这个DSBridge 和我之前开发做的混合开发 用的方式 很相似,所以觉得很是不错,推荐给你大家. DSBridge-IOS:https://github.com/wendux/DSBridge-IO ...
- hadoop开发环境部署——通过eclipse远程连接hadoop2.7.3进行开发
一.前言 环境: 系统:centos6.5 hadoop版本:Apache hadoop2.7.3(Windows和centos都是同一个) eclipse版本:4.2.0(juno版本,window ...
- 商业级别Fortify白盒神器介绍与使用分析
转自:http://www.freebuf.com/sectool/95683.html 什么是fortify它又能干些什么? 答:fottify全名叫:Fortify SCA ,是HP的产品 ,是一 ...
- 无废话 Thrift 之 Hello World( PHP 版).
Thrift 不再介绍.体验一把 PHP 的Server , PHP 的Client. 0.安装,装备环境,不表,运行 thrift -version 看到版本就行. 1.写 HelloThrift. ...
- Reading——简约至上
读书感言: 简约至上——Giles Colborne,我去,这是哪里来的渣书,通篇都是泛泛而谈,实在受不鸟了> <,没学到啥实质性的东西,论述一大堆.!!!还姐的20多块钱.最讨厌这样的书 ...
- 【转】ConcurrentMap 分析和思考
预备知识:Java HashMap and HashSet 的实现机制 由预备知识可以知道hashmap 的存储结构为: (图像来自http://www.ibm.com/developerworks/ ...
- PM2部署资料
问题1:pm2的log怎么查看?(pm2 show (name))可以看到日志地址,直接查看 问题2:日志怎么清除:pm2 flush 问题3:修改日志输出路径 问题4:怎么重新加载,restart貌 ...
- CentOS7 安装Maven3
下载安装文件 cd /root wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache- ...
- Unable to locate JAR/zip in file system as specified by the driver definition: ojdbc14.jar
eclipse的配置错误,把当前包删除,重新导入一个包.然后设置与需要的数据库对应,就可以了