Python批量修改word文档详解编程语言
2023-06-13 09:20:23 时间
-----------------------------------------------------------------------------------
2015.07.16 Grey
***********************************************************************************
Use the win32com to process word document and generate a set of ENW documents.
import win32com,os,re,time,datetime,string
from win32com.client import Dispatch,constants
def enw_documents_generate(document_name):
enw_document_type = raw_input("Please input the type for ENW Doc (E/e for electronic and others for paper):").upper()
pwd = os.getcwd()
document_list = []
hex_list = []
pack_flag_for_replace = pack_name
word_app = win32com.client.Dispatch(Word.Application)
word_app.Visible = 0
word_app.DisplayAlerts = 0
document_name = pwd + // + document_name
base_time = time.strftime(%Y_%m_%d,time.localtime(time.time()))
date_today = datetime.datetime(string.atoi(base_time[0:4]),string.atoi(base_time[5:7]),string.atoi(base_time[8:10]))
date_three_days_later = date_today + datetime.timedelta(days = 85)
date_today_str = re.sub(r 00.00.00,,str(date_today))
date_three_days_later_str = re.sub(r 00.00.00,,str(date_three_days_later))
date_today_str = re.sub(r(/d/d/d/d)-(/d/d)-(/d/d),r/2//3//1,date_today_str)
date_three_days_later_str = re.sub(r(/d/d/d/d)-(/d/d)-(/d/d),r/2//3//1,date_three_days_later_str)
#document = word_app.Documents.Open(FileName = document_name)
#word_app.Selection.Find.ClearFormatting()
#word_app.Selection.Find.Replacement.ClearFormatting()
for root,dirs,files in os.walk(.):
hex_list = [f for f in os.listdir(.) if f.endswith(.rar)]
for hex_file in hex_list:
pack_name = re.sub(.rar,,hex_file)
document = word_app.Documents.Open(FileName = document_name)
word_app.Selection.Find.ClearFormatting()
word_app.Selection.Find.Replacement.ClearFormatting()
word_app.Selection.Find.Execute(pack_name, False, False, False, False, False, True, 1, True, pack_name, 2)
word_app.Selection.Find.Execute(today, False, False, False, False, False, True, 1, True, date_today_str, 2)
if enw_document_type == E:
word_app.Selection.Find.Execute(Three_days_later, False, False, False, False, False, True, 1, True, , 2)
else :
word_app.Selection.Find.Execute(Three_days_later, False, False, False, False, False, True, 1, True, date_three_days_later_str, 2)
document.SaveAs(pwd + // + CTENW_ + pack_name +.docx)
#document.Close()
word_app.Documents.Close()
word_app.Quit()
enw_documents_generate(ENW_temp.docx)
print "All the ENW documents has been generated!"
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8118.html
cpython相关文章
- Python 调用接口进行文件上传的踩坑记录
- 如何为pycharm配置Python解释器_pycharm选择python解释器
- python meshgrid_numpy的生成网格矩阵 meshgrid()
- Python入门系列(六)一篇学会python函数
- python aes ecb_python简单加密
- 【说站】python双向链表的概念介绍
- 【说站】python创建可变变量的方法
- Python抛出异常_python抛出异常的作用
- python如何安装sklearn库
- Miniconda管理多版本python环境
- Python:利用python代码编程实现将视频的avi格式转换为MP4格式
- python上的表白代码_用Python实现表白代码
- pycharm如何调试python程序_Pycharm断点调试Python程序的步骤方法
- 【1】windows系统如何安装后缀是whl的python库
- FastAPI从入门到实战(1)——Python类型提示
- 软件测试|教你使用Python快速绘制酷炫词云图
- Python互联网大数据爬虫的武汉市二手房价格数据采集分析:Linear Regression模型、XGBoost模型和LightGBM模型
- python-数据库编程-如何在Python中连接到数据库
- Python比较运算符(关系运算符)
- python十进制转二进制,可指定位数详解编程语言
- 使用Python执行Linux命令的方法(python调用linux命令)
- Linux下安装Python程序与PIP的指南(linuxpythonpip)
- 搞定!Linux下快速设置Python环境变量(linux设置python环境变量)
- 快速安装Python MySQL模块(python安装mysql模块)
- Linux下快速修改PIP源加速安装Python库(linux修改pip源)
- python编程-将Python程序转化为可执行程序[整理]
- Python拷贝对象(深拷贝deepcopy与浅拷贝copy)