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

建设vip网站相关视频下载微信sdk

建设vip网站相关视频下载,微信sdk,wordpress-5.0升级未被安装,镇网站建设管理工作总结作品展示 背景需求#xff1a; 制作“育儿知识#xff08;家园小报#xff09;”#xff0c;查询发现去年就没有做 因为“家园小报”基本没有段落文字#xff0c;都是“文本框文字、艺术字“#xff0c;很难用python提取文字。 由于只有6篇#xff0c;因此去年采用的就…作品展示 背景需求 制作“育儿知识家园小报”查询发现去年就没有做 因为“家园小报”基本没有段落文字都是“文本框文字、艺术字“很难用python提取文字。 由于只有6篇因此去年采用的就是手动贴文字到excel表格中再用word模板批量的方法 今年尝试用python读取word文本框文字还是显示为空 所以和去年一样手动复制word,制作excel内容. 本学年墙面贴的是“育儿知识”A4竖版 将两份代码合并 主要步骤 1、doc更改统一文件名长度 2、doc转docx 3、docx去掉回车符空行发现内部都是文本框清除回车后整个文本框都删光了 4、手动提取word内容导入EXCEL 5、在word模板里将EXCEL内容填入保存多个docx 6、把docx转成png 6、把1张png切割成2张png班级主页 素材准备 都是“03 育儿知识 ”下的内容 第01步修改文件名  把文件名改成”2024年02月 家园小报.doc“ 代码展示 微调部分——统计文件名的长度 import os import timepath rD:\test\02办公类\91周计划4份_2024年中4班\03 育儿知识\01docfileListos.listdir(path)print(fileList)for file in fileList: # 如果格式不统一 提取所有的周次split_str file.split(月)newname1 split_str[0] # _的第0部分序号 print(newname1)# newname2 split_str[1] # _的第0部分序号 # print(newname2)newname2024年newname1月 家园小报.docoldname_path os.path.join(path,file)# 文件新路径newname_path os.path.join(path,newname)# 新旧对调os.rename(oldname_path, newname_path)# 2023年2周 家园小报.doc 16字符# 延时 time.sleep(2)fileListos.listdir(path)for file in fileList: if len(file)16: #2023年2周 家园小报.doc 16字符 16是一位数的周次 print(file) split_str file.split(年)newname1 split_str[0] # _的第0部分序号 print(newname1)newname2 split_str[1] # _的第0部分序号 print(newname2)newnamenewname1年0newname2oldname_path os.path.join(path,file)# 文件新路径newname_path os.path.join(path,newname)# 新旧对调os.rename(oldname_path, newname_path)if len(file)17: # 2023年12周 家园小报.doc 16字符 17是两位数的周次 pass 终端显示 第2步原有文件格式从doc变成docx 代码展示——doc文件下的19个doc转到docx文件下的19个docx import os from win32com import client as wc import time # 注意目录的格式必须写成双反斜杠 pathrD:\test\02办公类\91周计划4份_2024年中4班\03 育儿知识 oldpathpathr\01doc # 使用绝对地址可更改原文件doc地址 newpathpathr\02docx# 使用绝对地址可更改docx地址# 提取所有doc内的19周doc周计划的路径 files[] for file in os.listdir(oldpath):# 找出文件中以.doc结尾并且不以~$开头的文件~$是为了排除临时文件if file.endswith(.doc) and not file.startswith(~$): files.append(oldpath\\file)print(files)# 打开doc文件下的doc文件另存到docx文件下的docx文件 for file in files:word wc.Dispatch(Word.Application)print(已处理文件file) # # # 打开文件doc word.Documents.Open(file) # # # 将文件另存为到docx文件夹另存为.docx# # 这里根据文件名称长度进行数字确定# 2023年06周 家园小报.doc 一共17字符newnewpath\\file[-17:]xprint(new)doc.SaveAs({}.format(new), 12) # 12表示docx格式doc.Close() 第3步删除docx里面的回车符 删除回车符就把原来的“家园小报”里面所有的文本框都删掉了 这里先跳过。 第4步整理“主题知识”的EXCEL信息手动写入 中4班下学期“主题知识”.xlsx 打开每一个word 选取标题和内容每页上有2套 同样方法复制所有文本框里的内容。 EXCEL里面有特殊格式 空格顿号、可以用程序批量删除修改 代码展示 # https://blog.csdn.net/lau_jw/article/details/114383781from docx import Document from openpyxl import load_workbook import glob import re# 将模板 Excel 读取进程序 path rD:\test\02办公类\91周计划4份_2024年中4班\03 育儿知识 workbook load_workbook(path r\10 改周次过渡模板_育儿知识.xlsx) sheet workbook.active# 手动贴入信息print(--打开XLSX-,把里面的空格删除把1、替换成1.--)# # 打开Excel文件 workbook load_workbook(path r\11 中4班下学期_育儿知识.xlsx) # 获取第一个工作表 worksheet workbook.active# # 遍历每个单元格 for row in worksheet.iter_rows():for cell in row: if cell.value and isinstance(cell.value, str): # 清除单元格内文字的格式cell.value cell.value.strip()# 判断单元格中的文字是否有空格if in str(cell.value):# 替换空格为无空格cell.value str(cell.value).replace( , )if   in str(cell.value):# 替换空格为无空格cell.value str(cell.value).replace( , )# 替换文本for s in range(1,10):if cell.value and isinstance(cell.value, str):cell.value cell.value.replace({}、.format(s), {}..format(s))# 保存修改后的Excel文件 workbook.save(path r\11 中4班下学期_育儿知识.xlsx)# 关闭Excel文件 workbook.close()# number 0# # 提取四个加粗标题所在的行数 # 参考https://www.shouxicto.com/article/96876.html# for file in glob.glob(path r\03去掉回车\*.docx): # print(file)# doc Document(file)# #获取每个文档的行数 # # print(段落数:str(len(doc.paragraphs)))#段落数为13每个回车隔离一段 # dlen(doc.paragraphs)# # 保存所有段落文字的列表 # # 保存所有段落文字的列表 # paragraphs []# # # 遍历文档中的段落并将文字添加到列表中 # # for paragraph in doc.paragraphs: # # paragraphs.append(paragraph.text)# # # 遍历文档中的内联形状提取文本框文字并添加到列表中 # # for shape in doc.inline_shapes: # # if shape.text_frame: # # paragraphs.append(shape.text_frame.text) # # print(paragraphs)# # 提取word文本框中文本# children file.element.body.iter() # child_iters [] # for child in children: # # 通过类型判断目录 # if child.tag.endswith(textbox): # for ci in child.iter(): # if ci.tag.endswith(main}r): # child_iters.append(ci) # textbox [ci.text for ci in child_iters] # print(textbox)# # number 1 # # # sheet.append([number, content1,content2,content3,content4]) # number是序号一共遍历提取了几分Word的内容content是育儿知识中间部分的内容# # sheet.cell(rownumber1, column1).value number # # sheet.cell(rownumber1, column2).value content1 # # sheet.cell(rownumber1, column3).value content2 # # sheet.cell(rownumber1, column4).value content3 # # sheet.cell(rownumber1, column5).value content4# # workbook.save(path r\11 中4班下学期_育儿知识.xlsx) # # workbook.close() 结果展示 第5步读取word模板把EXCEL-育儿知识 的内容 合成6份 Docx 代码展示 # 一、导入相关模块设定excel所在文件夹和生成word保存的文件夹 from docxtpl import DocxTemplate import pandas as pd import os import xlwt import xlrd import os import random from win32com.client import constants,gencache from win32com.client.gencache import EnsureDispatch from win32com.client import constants # 导入枚举常数模块 import os,time import docx from docx import Document from docx.shared import Pt from docx.shared import RGBColor from docx.enum.text import WD_PARAGRAPH_ALIGNMENT# pathrD:\\test\\02办公类\\90周计划4份\\06 信息窗主题知识\\ path rD:\test\02办公类\91周计划4份_2024年中4班\06 信息窗主题知识 print(path)file_pathpathr\04合成新信息窗主题知识 print(file_path)# 二、遍历excel逐个生成word小标签.docx是前面的模板 try:os.mkdir(file_path) except:passlist pd.read_excel(path\\11 中4班下学期_信息窗主题知识.xlsx) # 信息窗 title list[title].str.rstrip() name list[name] contentlist[content].str.rstrip()# 没有str.rstrip()是数字格式 classroom list[classroom].str.rstrip() # str.rstrip()都是文字格式 T1 list[T1].str.rstrip() # 没有str.rstrip()是数字格式 T2 list[T2].str.rstrip()# 没有str.rstrip()是数字格式 timelist[time].str.rstrip() # 主题知识 titlename list[titlename].str.rstrip() name1list[name1] smlist[sm].str.rstrip()# 没有str.rstrip()是数字格式 mblist[mb].str.rstrip()# 没有str.rstrip()是数字格式 gylist[gy].str.rstrip()# 没有str.rstrip()是数字格式 classroom1 list[classroom1].str.rstrip() # str.rstrip()都是文字格式 # T1 list[T1].str.rstrip() # 没有str.rstrip()是数字格式 # T2 list[T2].str.rstrip()# 没有str.rstrip()是数字格式 time1list[time1].str.rstrip() # 遍历excel行逐个生成 num list.shape[0] for i in range(num):context {title: title[i],content: content[i], classroom: classroom[i],name :name[i],T1: T1[i],T2: T2[i], time: time[i], name1: name1[i],titlename: titlename[i],sm: sm[i], mb :mb[i],gy :gy[i], classroom1: classroom1[i], time1: time1[i], }tpl DocxTemplate(path\\12 信息窗主题知识_竖版双.docx)# tpl DocxTemplate(path\\12 信息窗主题知识_横版双.docx)tpl.render(context)# tpl.save(file_pathr\\第{}周 {}班 信息窗{}.docx.format(%02d%name[i],classroom[i],time[i]))tpl.save(file_pathr\\第{}周 {}班 信息窗主题知识{}.docx.format(%02d%name[i],classroom[i],time[i])) 运行结果 打开手动清除不要的内容、调整首行缩进、控制字数多少与版面样式不需要手码日期了(*^_^*) 第6步把育儿知识”转为png格式a4竖版板一页 代码展示 作者毛毛 性质转载 原网址 https://zhuanlan.zhihu.com/p/367985422安装python确保以下模块已经安装win32comfitzre 在桌面新建文件夹命名为word2pdf2png 将需要转换的word只能docx格式可以多个放入文件夹word2pdf2png 复制以下代码并运行。本代码只生成png 文件夹内只有一级子文件不生成说明 1、 2、把“03 新周计划生成原版”的内容复制到“04 新周计划没有反思的打印” 3、把“04 新周计划没有反思的打印”内容复制到“05 新周计划没有反思的jpg上传” 4、然后“05 新周计划没有反思的jpg上传”文件夹删除并生成第一张无反思的图片20份 5、空余时间。把““03 新周计划生成原版”文件夹的内容复制到“08 新周计划生成手动修改-准”文件夹手动修改 1周计划第一页反思限定在一页内 2教案等#codingutf-8 from win32com.client import Dispatch import os import re import fitz wdFormatPDF 17 #转换的类型 zoom_x2 #尺寸大小越大图片越清晰 5超大这里改成2 zoom_y2 #尺寸大小越大图片越清晰长宽保持一致 rotation_angle0#旋转的角度0为不旋转# print(----把04合成新育儿知识文件夹里的资料复制到05jpg上传-----)import os import shutildef copy_docx_files(source_dir, dest_dir):for filename in os.listdir(source_dir):source_path os.path.join(source_dir, filename)dest_path os.path.join(dest_dir, filename)if os.path.isfile(source_path) and filename.endswith(.docx):shutil.copy(source_path, dest_path)if os.path.isdir(source_path):copy_docx_files(source_path, dest_dir)# 指定源文件夹和目标文件夹 old_pat rD:\test\02办公类\91周计划4份_2024年中4班\03 育儿知识\04合成新育儿知识 # 要复制的文件所在目录 new_path rD:\test\02办公类\91周计划4份_2024年中4班\03 育儿知识\05jpg上传 #新路径# 调用复制函数 copy_docx_files(old_pat, new_path)#print(----生成PDF和第一页图片-----) def doc2pdf2png(input_file):for root, dirs, files in os.walk(input_file):for file in files:if re.search(\.(docx|doc)$, file):filename os.path.abspath(root \\ file)print(filename, filename)word Dispatch(Word.Application)doc word.Documents.Open(filename)doc.SaveAs(filename.replace(.docx, .pdf), FileFormatwdFormatPDF)doc.Close()word.Quit()for root, dirs, files in os.walk(input_file):for file in files:if re.search(\.pdf$, file):filename os.path.abspath(root \\ file)print(filename, filename)# 打开PDF文件pdf fitz.open(filename)# 逐页读取PDFfor pg in range(0, pdf.pageCount):page pdf[pg]# 设置缩放和旋转系数trans fitz.Matrix(zoom_x, zoom_y).preRotate(rotation_angle)pm page.getPixmap(matrixtrans, alphaFalse)# 开始写图像pm.writePNG(filename.replace(.pdf, ) str(pg1) .png)pdf.close()doc2pdf2png(new_path)# 删除生成文件PDF 和 生成文件docx for parent, dirnames, filenames in os.walk(new_path):for fn in filenames:if fn.lower().endswith(.pdf):os.remove(os.path.join(parent, fn))if fn.lower().endswith(.docx):# 删除原始文件docx 正则[pdf|docx]套不上只能分成两条了os.remove(os.path.join(parent, fn))# 删除png中尾号是2-8的pngWord只要第一页后面生成的第二页图片不要 for parent, dirnames, filenames in os.walk(new_path):for fn in filenames:for k in range(2,9): # png文件名的尾数是2,34,5,6,7,8 不确定共有几页可以把9这个数字写大一点if fn.lower().endswith(f{k}.png): # 删除尾号为2,3,4,5,6,78的png图片 f{k}{}.formart(k) os.remove(os.path.join(parent, fn)) 图片结果展示 先出现word和PDF、最后出现一张图片 说明由于每次选用的word原素材格式、内容、结构都不同所以最好把代码分成6个逐一调整路径、内容选择范围等。这是个很细致的活儿。
http://www.zqtcl.cn/news/288571/

相关文章:

  • 某某公司网站建设论文wordpress 企业 主题
  • 网站提示域名解析错误怎么办百度网址提交
  • 福建省住房城乡建设部网站车公庙网站建设
  • 长沙网站seo诊断ip138禁止查询该域名
  • 大学生网站设计作业动画ftp发布asp.net网站
  • 网站建设哪家企业好站内优化怎么做
  • 萌宝宝投票网站怎么做网上商城推广方法
  • 网站建设规划书样板社交电商
  • 网站怎么做直播功能吗水库信息化网站建设
  • c语言做网站账号登录系统外资公司代理注册
  • 建站公司塔山双喜做饲料推广哪个网站好
  • php网站后台入口拼多多海外跨境电商入驻流程
  • 0731网站平面logo设计公司
  • 网站设计制作报价图片欣赏wordpress福利
  • 网站上有什么作用自己做网站需要学什么
  • 在哪里做马可波罗网站wordpress中文站cn
  • 威海外贸建站制作游戏的平台
  • 网站栏目策划 有思想的新闻网站建设开发的流程
  • 网站描述修改潍坊百度网站排名
  • 网站开发设计的技术网站开发可能存在的困难
  • 单片机做网站网站地图那么建设
  • 手机版网站建设软件wordpress主题开发ide
  • 网站建设的技术有哪些内容网站推广优化排名
  • 网站开发用jsp网站开发需要什么技术
  • 网站打开404错误怎么解决网站开发树形图
  • 好的建设网站公司哪家好湖南省做网站的
  • 网站怎么上传网站建设可行性分析表
  • 东营做网站优化价格企业网站开发一般多少钱
  • 高端网站设计公司排名邢台哪里有做网站的
  • 广州网站开发 英诺科技营销式网站建设