当前位置: 首页 > news >正文

青岛做公司网站的多吗wordpress 头像 virtos

青岛做公司网站的多吗,wordpress 头像 virtos,深圳市建设招标网,开发公司与物业公司前期合同需求#xff1a;修改指定目录下所有文件的页眉页脚#xff0c;或者往里面添加内容。 1. 这里做了word的实现和excel的实现#xff0c;如下#xff1a; 需要先安装 pip3 install pywin32#xff0c;另外页眉页脚格式设置可以参考#xff1a; word#xff1a; 浅谈Wor…需求修改指定目录下所有文件的页眉页脚或者往里面添加内容。 1. 这里做了word的实现和excel的实现如下 需要先安装 pip3 install pywin32另外页眉页脚格式设置可以参考 word 浅谈Word.Application关于js操作word文档的使用_new word.application-CSDN博客 excel Python操作Excel教程图文教程超详细Python xlwings模块详解_xlwings教程-CSDN博客 import os import xlwings as xw import win32com.client as win32 import pythoncom#将需要替换页眉页脚的文档放到path下 path rC:\Users\d\Desktop\pdf改名脚本\22\2022年\test #原始页眉页脚内容 old_name u999 #新页眉页脚内容 new_name u888 #替换失败记录日志 err_log path u\\head修改出错列表.txt def log(text):with open( err_log,a ) as f:f.write(text)f.write(\n)def change_headerfooter(path): 更改文件的页眉页脚 pythoncom.CoInitialize()word win32.Dispatch(Word.Application)#print(dir(word))word.Visible 0word.DisplayAlerts 0exapp xw.App(visibleFalse, add_bookFalse)# excel win32.Dispatch(Excel.Application)# excel.Visible 0# excel.DisplayAlerts 0for parent, dirnames, filenames in os.walk(path):for fn in filenames:filedir os.path.join(parent, fn)#获取需替换目录下的docx结尾的文档名称if fn.endswith(.docx) or fn.endswith(.doc):print(filedir)try:doc word.Documents.Open( filedir )a word.ActiveDocument.Sectionsn 0for i in range( len(a) ):#获取当前页眉head word.ActiveDocument.Sections[i].Headers[0]old_head str(head)#获取当前页脚foot word.ActiveDocument.Sections[i].Footers[0]old_foot str(foot)#print( old_head )#if old_name in old_head:if 1:#old_name存在页眉中时进行进行替换#用于替换页眉#new_head old_head.replace( old_name, new_name )#用于补充页眉#new_head old_head new_name#print( new_head )word.ActiveDocument.Sections[i].Headers[0].Range.Find.ClearFormatting()word.ActiveDocument.Sections[i].Headers[0].Range.Find.Replacement.ClearFormatting()#页眉重置word.ActiveDocument.Sections[i].Headers[0].Range.Delete()#设置字体大小word.ActiveDocument.Sections[i].Headers[0].Range.Font.Size20#设置对齐方式0-左1-中2-右word.ActiveDocument.Sections[i].Headers[0].Range.ParagraphFormat.Alignment 0word.ActiveDocument.Sections[i].Headers[0].Range.InsertAfter(new_name)#替换旧页眉#word.ActiveDocument.Sections[i].Headers[0].Range.Find.Execute( old_head, False, False, False, False, False, False, 1, False, new_name, 2 )#if old_name in old_foot:if 1:##old_name存在页脚中时进行进行替换#new_foot old_foot.replace( old_name, new_name )#new_foot old_foot new_nameword.ActiveDocument.Sections[i].Footers[0].Range.Find.ClearFormatting()word.ActiveDocument.Sections[i].Footers[0].Range.Find.Replacement.ClearFormatting()#页脚重置word.ActiveDocument.Sections[i].Footers[0].Range.Delete()word.ActiveDocument.Sections[i].Footers[0].Range.InsertAfter(new_name)#替换旧页脚#word.ActiveDocument.Sections[i].Footers[0].Range.Find.Execute( old_foot, False, False, False, False, False, False, 1, False, new_name, 2 )n n1doc.Close()except Exception as e:print(e)log(str(filedir))if fn.endswith(.xlsx) or fn.endswith(.xls):print(filedir)try:ex exapp.books.open(filedir)#print(dir(ex.sheets))sheet ex.sheetsprint(sheet[0].name)if test sheet[0].name:print(sheet.name)else:#如果第一个sheet不是test则加一个test的sheetsheet.add(test,beforesheet[0].name)ex.save()ex.close()except Exception as e:log(str(filedir))word.Quit()exapp.quit()change_headerfooter(path) 补充一下excel没有用pywin32去读写因为莫名其妙就是卡进程无法对excel读写可能和缓存的excel有关如要编辑3.xlsx则会卡一个~3.xlsx的进程无法结束。就换成了xlwings去读写。
http://www.hkea.cn/news/14555815/

相关文章:

  • 广州商城网站建设移动门网站建设
  • 合肥公司建设网站首页360免费建站永久免费
  • 虚拟主机销售网站模板网页图片文字识别
  • 孟村网 网站北京网站制作网站
  • 网站建设怎么入会计账中小型企业建设网站
  • 无为做网站ui设计已经不火了
  • app小程序网站开发是什么纪念币商城网站建设
  • 做网站首页置顶多少钱网站改版对网站优化影响最大的问题是什么
  • 打开山东城市建设职业学院网站设计资料网站
  • 建设部网站实名制举报查企业用什么软件
  • 泉州网站的建设笑傲网站建设
  • 为什么企业需要建设网站?萧山网页设计
  • 专业的网站建设公司电话贵阳建设工程招投标网站
  • 用iis建立网站以网站建设专业画一幅画
  • 盱眙建设局网站可以做投票功能的网站
  • 江门骏科网站建设怎样找到免费的黄页网站
  • h5商城网站怎么建立连云港公司网站优化服务
  • 网站内容收录微信公众号推广目的
  • 盐城网站建设哈尔滨做网站多少钱
  • 四川做网站公司首页面设计的步骤
  • wordpress+网站白屏wordpress 文章打不开
  • 自建wap网站全栈网站开发工程师
  • 天河建设网站设计seo站群系统
  • 网站维护服务网站设计分工
  • 做国际网站花钱吗网站创建需要什么
  • 建设银行锦州分行网站wordpress 多站点共享
  • php做的网站源代码北京土巴兔装修公司电话
  • 梅州市住房和建设局网站wordpress当面付
  • 免费域名申请网站大全推荐拓者设计吧电脑版网页
  • 网站的建设任务电子政务门户网站建设汇报