推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
king625
V2EX  ›  Python

Python 如何在 docx 的指定位置插入图片,并设置图片大小?

  •  
  •   king625 · May 10, 2018 · 9515 views
    This topic created in 2927 days ago, the information mentioned may be changed or developed.

    想要在 docx 的指定位置插入结果图片,并且设置图片大小,最好可以在 table 的一个 cell 中插入图片,但是使用 python-docx 尝试,好像插入时只能插入在文件末端?

    qile1
        1
    qile1  
       May 10, 2018 via Android
    听说 docx 是个 zip 压缩了 xml 文件的文件,你先插入一个图片作为模板文件,然后替换图片可以不?
    king625
        2
    king625  
    OP
       May 11, 2018
    @qile1 谢谢, 后来翻了一下 python-docx 的 Issues,发现大神之前发布了解决方法,链接如下:
    https://github.com/python-openxml/python-docx/issues/10

    代码如下:
    paragraph = cell.paragraphs[0]
    run = paragraph.add_run()
    run.add_picture('image.png')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2955 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:01 · PVG 14:01 · LAX 23:01 · JFK 02:01
    ♥ Do have faith in what you're doing.