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

购物网站的排版垂直网站建设方案

购物网站的排版,垂直网站建设方案,网站编辑,服务器网站建设教程视频教程今天看见了一个有意思的脚本Python批量实现Word、EXCLE、PPT转PDF文件。 因为我平时word用的比较的多#xff0c;所以深有体会#xff0c;具体怎么实现的我们就不讨论了#xff0c;因为这个去学了也没什么提升#xff0c;不然也不会当作脚本了。这里我将其放入了pyzjr库中…今天看见了一个有意思的脚本Python批量实现Word、EXCLE、PPT转PDF文件。 因为我平时word用的比较的多所以深有体会具体怎么实现的我们就不讨论了因为这个去学了也没什么提升不然也不会当作脚本了。这里我将其放入了pyzjr库中也方便大家进行调用。 你可以去下载pyzjr: pip install pyzjr -i https://pypi.tuna.tsinghua.edu.cn/simple 调用方法 import pyzjr as pz# 实例化对象 Mpdf pz.Microsoft2PDF() # 调用类的方法 Mpdf.Word2Pdf() # word - pdf Mpdf.Excel2Pdf() # excel - pdf Mpdf.PPt2Pdf() # ppt - pdf Mpdf.WEP2Pdf() # word,excel,ppt - pdf 上面就是api的调用了统一会将文件存放在目标文件夹下新建的名为pdf文件夹中。 pyzjr中的源码 import win32com.client, gc, osclass Microsoft2PDF():Convert Microsoft Office documents (Word, Excel, PowerPoint) to PDF formatdef __init__(self,filePath )::param filePath: 如果默认是空字符,就默认当前路径self.flagW self.flagE self.flagP 1self.words []self.ppts []self.excels []if filePath :filePath os.getcwd()folder filePath \\pdf\\self.folder CreateFolder(folder,debugFalse)self.filePath filePathfor i in os.listdir(self.filePath):if i.endswith((.doc, docx)):self.words.append(i)if i.endswith((.ppt, pptx)):self.ppts.append(i)if i.endswith((.xls, xlsx)):self.excels.append(i)if len(self.words) 1:print(\n[pyzjr]:No Word files\n)self.flagW 0if len(self.ppts) 1:print(\n[pyzjr]:No PPT file\n)self.flagE 0if len(self.excels) 1:print(\n[pyzjr]:No Excel file\n)self.flagP 0def Word2Pdf(self):if self.flagW 0:return 0else:print(\n[Start Word -PDF conversion])try:print(Open Word Process...)word win32com.client.Dispatch(Word.Application)word.Visible 0word.DisplayAlerts Falsedoc Nonefor i in range(len(self.words)):print(i)fileName self.words[i] # file namefromFile os.path.join(self.filePath, fileName) # file addresstoFileName self.changeSufix2Pdf(fileName) # Generated file nametoFile self.toFileJoin(toFileName) # Generated file addressprint(Conversion: fileName in files...)try:doc word.Documents.Open(fromFile)doc.SaveAs(toFile, 17)print(Convert to: toFileName file completion)except Exception as e:print(e)print(All Word files have been printed)print(End Word Process...\n)doc.Close()doc Noneword.Quit()word Noneexcept Exception as e:print(e)finally:gc.collect()def Excel2Pdf(self):if self.flagE 0:return 0else:print(\n[Start Excel - PDF conversion])try:print(open Excel Process...)excel win32com.client.Dispatch(Excel.Application)excel.Visible 0excel.DisplayAlerts Falsewb Nonews Nonefor i in range(len(self.excels)):print(i)fileName self.excels[i]fromFile os.path.join(self.filePath, fileName)print(Conversion: fileName in files...)try:wb excel.Workbooks.Open(fromFile)for j in range(wb.Worksheets.Count): # Number of worksheets, one workbook may have multiple worksheetstoFileName self.addWorksheetsOrder(fileName, j 1)toFile self.toFileJoin(toFileName)ws wb.Worksheets(j 1)ws.ExportAsFixedFormat(0, toFile)print(Convert to: toFileName file completion)except Exception as e:print(e)# 关闭 Excel 进程print(All Excel files have been printed)print(Ending Excel process...\n)ws Nonewb.Close()wb Noneexcel.Quit()excel Noneexcept Exception as e:print(e)finally:gc.collect()def PPt2Pdf(self):if self.flagP 0:return 0else:print(\n[Start PPT -PDF conversion])try:print(Opening PowerPoint process...)powerpoint win32com.client.Dispatch(PowerPoint.Application)ppt Nonefor i in range(len(self.ppts)):print(i)fileName self.ppts[i]fromFile os.path.join(self.filePath, fileName)toFileName self.changeSufix2Pdf(fileName)toFile self.toFileJoin(toFileName)print(Conversion: fileName in files...)try:ppt powerpoint.Presentations.Open(fromFile, WithWindowFalse)if ppt.Slides.Count 0:ppt.SaveAs(toFile, 32)print(Convert to: toFileName file completion)else:print(Error, unexpected: This file is empty, skipping this file)except Exception as e:print(e)print(All PPT files have been printed)print(Ending PowerPoint process...\n)ppt.Close()ppt Nonepowerpoint.Quit()powerpoint Noneexcept Exception as e:print(e)finally:gc.collect()def WEP2Pdf(self):Word, Excel and PPt are all converted to PDF.If there are many files, it may take some timeprint(Convert Microsoft Three Musketeers to PDF)self.Word2Pdf()self.Excel2Pdf()self.PPt2Pdf()print(fAll files have been converted, you can find them in the {self.folder})def changeSufix2Pdf(self,file):将文件后缀更改为.pdfreturn file[:file.rfind(.)] .pdfdef addWorksheetsOrder(self,file, i):在文件名中添加工作表顺序return file[:file.rfind(.)] _worksheet str(i) .pdfdef toFileJoin(self, file):将文件路径和文件名连接为完整的文件路径return os.path.join(self.filePath, pdf, file[:file.rfind(.)] .pdf) 这里我对原先博主的代码进行了一定的优化使其可供我们调用。 这是控制台打印出来的信息我们可以发现在调用WEP2Pdf时如果当前文件夹中没有word的文件也能继续去转换。
http://wiki.neutronadmin.com/news/12319/

相关文章:

  • 网站开发语言为 php帮朋友免费做网站
  • 湖北皇奥建设工程有限公司网站新浪微博网页版
  • 企业网站建设需要考虑内容爱站网新网址是多少
  • 济南外贸网站制作深圳广告设计公司网站
  • 网站建设落地页北京住建个人证书查询网
  • 营销型网站跟云网站阿里巴巴国际站做2个网站有用
  • 青岛网站建设团队电脑优化软件推荐
  • 广州网站建设比较好的公司在哪可以找到做网站的
  • 网站建设与优化推广方案手机做任务网站
  • 中国建设劳动协会网站定制型网站建设平台
  • php网站开发图文教程小程序登录跳转
  • php做网站最容易网站没被收录怎么办
  • 深圳上市公司全部名单杭州seo网站
  • 哪些网站论坛做推广好河南网站建设yipinpai
  • 网站建设方案书生鲜重庆建设传动科技有限公司
  • 哈尔滨手机网站建设价格邢台seo技术
  • 科技风格设计网站中山做网站公司
  • qingdao城乡住房建设厅网站大连模板网站制作电话
  • 建立个人网站怎么赚钱cms系统复杂权限
  • 网站图片设计怎样才能高大上辽阳网站建设公司
  • 郑州个人网站建设装修全包
  • 想自己做网站需要会什么品牌整合营销传播方案
  • 网站建设方维企业网站源码asp
  • 有网站模板怎么做网站网站美工做确认取消对话框
  • 怎么做好网站狠抓措施落实
  • 怎么把自己做的网站放到网上网站移动端指的是什么
  • 做番号网站犯法吗百度网址大全官网下载
  • 网站首页怎么做营业执照链接开发一款app软件怎么赚钱
  • 太原网站建设设计李沧做网站
  • 网站建设介绍书茂名网站建设推广