如何使用python在docx中修改custom.xml [英] How to modify custom.xml within docx using python

查看:72
本文介绍了如何使用python在docx中修改custom.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用python-docx来以编程方式更改需要每月更新的word文档(* .docx)的部分.现在,我的问题在于编辑模板中的自定义属性,特别是完成日期"属性.

I've been using python-docx to programmatically change parts of a word document (*.docx) that needs to be updated monthly. My problem now lies with editing custom properties in the template, specifically the 'Date Completed' property.

自定义模板属性

我当前的简化python代码如下:

My current simplified python code is as follows:

import python-docx
doc = docx.Document('MonthlyUpdate.docx')
help(doc.core_properties)  #only shows author, category, etc, but no 'Date Completed'

相关文件似乎位于* .docx \ docProps \ custom.xml 中,但是我不确定如何在python 2.7中编辑该文件.是否可以通过python-docx还是我需要深入研究lxml/etree模块?

The relevant file appears to be in *.docx\docProps\custom.xml, but I'm unsure of how to edit that file within python 2.7. Is it possible through python-docx or would I need to dive into lxml/etree modules?

推荐答案

此功能尚未实现.有一个功能请求正在打开,并且一个用户已经对其进行了一些工作,您可以从那里找到链接.

This functionality hasn't been implemented yet. There's a feature request open for it and one user has done some work on it you can find linked to from there.

https://github.com/python-openxml/python-docx/Issues/91

我认为这需要使用他的fork,因此您可能无法获得所有最新功能,具体取决于fork所基于的版本.

I think this would require using his fork, so you might not get all the latest features, depending on the version the fork is based on.

这篇关于如何使用python在docx中修改custom.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆