#!/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的更多相关文章

  1. 【c#搬砖记】用Docx导出word格式的docx文件

    DocX开源网址:http://docx.codeplex.com/ 1.引入DocX.dll 调用ReplaceText()方法替换模板中的字符.只支持docx格式的word文档 using (Do ...

  2. C#通过模板导出Word的两种方法(超简单)

    方法一:使用Office的组件 使用该方法必须要安装Office 1.制作Word模板 在需要填充内容的地方增加标识符号,方便之后替换使用,例如 [项目名称],其中[]符号和中间的文字可根据个人情况进 ...

  3. Python 使用 win32com 模块对 word 文件进行操作

    what's the win32com 模块 win32com 模块主要为 Python 提供调用 windows 底层组件对 word .Excel.PPT 等进行操作的功能,只能在 Windows ...

  4. 太方便了!利用Python对批量Pdf转Word

    在wps或者office里面可以将pdf转word,不过只能免费转前面5页,超过5页就需要会员.今天教大家一个Python办公小技巧:批量Pdf转Word ,这样可以自由想转多少页都可以. 思路:这里 ...

  5. 用Python编写博客导出工具

    用Python编写博客导出工具 罗朝辉 (http://kesalin.github.io/) CC 许可,转载请注明出处   写在前面的话 我在 github 上用 octopress 搭建了个人博 ...

  6. C#导出Word文档开源组件DocX

    1.帮助文档,这东西找了很久,而且它版本很旧,还是英文,W8.1系统上打不开 http://download.csdn.net/detail/zuofangyouyuan/7673573 2.开源网址 ...

  7. python打造漏洞数据导出工具

    功能 [x] 支持导出的数据:IP地址.漏洞名称.风险等级.整改建议.漏洞描述.漏洞CVE编号.漏洞对应端口.漏洞对应协议.漏洞对应服务等. [x] 导出不同端口的同一个漏洞,也就是一个端口对应一个漏 ...

  8. python生成requirements.txt 导出项目依赖

    使用pip freeze $ pip freeze > requirements.txt 这种方式是把整个环境中的包都列出来了,如果是虚拟环境可以使用. 通常情况下我们只需要导出当前项目的req ...

  9. python将字典列表导出为Excel文件的方法

    将如下的字典列表内容导出为Excel表格文件形式: ​ 关于上图字典列表的写入,请参考文章:https://blog.csdn.net/weixin_39082390/article/details/ ...

  10. poi导出word文档,doc和docx

    maven <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --><dependency> <gro ...

随机推荐

  1. Java-Properties文件读取工具类

    import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configurat ...

  2. Opencv3 图片膨胀与腐蚀

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  3. ChainOfResponsibilityPattern(23种设计模式之一)

    参考书籍:设计模式-可复用面向对象软件基础(黑皮书) 目的:使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这些对象连成一条链,并沿这条链传递该请求,直到有一个对象处理它为止 ...

  4. [C++] c language 23 keywords

       c language keywords

  5. 虚拟机上linux与windows之间复制粘贴

    参考:https://blog.csdn.net/qq_34501940/article/details/51222119

  6. 黑盒测试实践-任务进度-Day04

    任务进度11-29 使用工具 selenium 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 经过了前两天的学习任务的安排,以下是大家的任务进度: 华同学(任务1) 1.和其他小 ...

  7. Sublime Text 2 安装配置插件

    最近学习python,看网上推荐用sublime text2挺方便,就学习了一下对sublime text2 安装插件,先放在这里,以备以后查找 根据晚上资料修改,原文请看这里 Python的自动补全 ...

  8. Ubuntu14.04下使用PPA安装php5.6,php7

    1.为了使用ppa(Personal Package Archives) 选安装依赖: # apt-get install python-software-properties 2.添加不同版本php ...

  9. C++学习--第一个程序

    C++控制台应用程序 我们创建一个包含预编译头的C++控制台应用程序时,会发现其结构是这样的: 1)理解预编译头文件: 所谓头文件预编译,就是把一个工程(Project)中使用的一些MFC标准头文件( ...

  10. React Native开发环境的搭建

    我只能说搭建开发环境还是不能相信网上纷乱的博客,还是中文网靠谱. http://reactnative.cn/docs/0.47/getting-started.html 纯粹只是为了记录一下.