Code example of Python implementing batch text content replacement of doc and docx

This article mainly explains how to replace doc and docx batch text content through python and three-party libraries.
Date: May 10, 2023
Author: Ren Congcong
python3.9 version

prerequisite preparation

Install: docx, win32

pip install 包名

Introduce:

import win32com.client as win32
import docx

actual effect

You can modify documents containing pictures, tables and other types of content in doc and docx, and modify text in batches without garbled characters.

Doc, docx document content before modification

insert image description here
insert image description here

The effect after modification of doc and docx is as follows, converting 2 into pairs

Guess you like

Origin blog.csdn.net/hj960511/article/details/130592153