背景
使用python-docx往word表格中插入图片 run.add_picture() ,保存后出现报错,未定义错误,/word/head1.xml line:0 column:0
解决代码

// An highlighted block
doc = Document(path)
doc_element = doc._element
docPrs = doc_element.findall('.//' + qn('wp:docPr'))
   for docPr in docPrs:
       # 增加id值以避免冲突
        current_id = docPr.get('id')
        if current_id is not None:
           new_id = str(int(current_id) + 100000)
            docPr.set('id', new_id)

doc.save(new_path)

更多推荐