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

网站建设主题有哪些注意事项怎么查百度收录

网站建设主题有哪些注意事项,怎么查百度收录,学设计需要多少钱,做网站用域名不备案怎么弄主要功能是按照JSON文件(Sort.json)中指定的顺序合并多个Word文档(.docx),并清除文档中的所有超链接。最终输出合并后的文档名为"sorted_按章节顺序.docx"。 主要分为几个部分: 初始化配置 定…

主要功能是按照JSON文件(Sort.json)中指定的顺序合并多个Word文档(.docx),并清除文档中的所有超链接。最终输出合并后的文档名为"sorted_按章节顺序.docx"。

主要分为几个部分:

初始化配置
  1. 定义超链接清除函数(处理段落+表格)
  2. 获取当前工作目录
读取排序规则
  1. 解析Sort.json文件
  2. 构建完整文件路径列表
文件验证
  1. 检查JSON中所有文件是否存在
  2. 输出缺失文件警告

主流程:读取JSON,验证文件,合并文档

环境配置步骤:

安装好 Python 和成功配置相应的环境变量,我的 Python 版本为 3.8.2
需要安装 win32com、docx、docxcompose,分别输入以下代码安装

pip install pypiwin32
pip install python-docx
pip install docxcompose
💡 提示:安装后可通过 python -c "import win32com; print('成功')" 验证

代码简略版:

!/usr/bin/python3.6
# -*- coding: utf-8 -*-
"""
@Time    :24-12 10:07
@Software: PyCharm
@Project :Merge files001
"""
import os
import json
from docx import Document
from docxcompose.composer import Composer# 清除文档中的所有超链接
def remove_hyperlinks(doc):for para in doc.paragraphs:for run in para.runs:# 通过run的XML属性查看是否为超链接if 'hyperlink' in run._r.xml:run._r.getparent().remove(run._r) for table in doc.tables:for row in table.rows:for cell in row.cells:for para in cell.paragraphs:for run in para.runs:if 'hyperlink' in run._r.xml:run._r.getparent().remove(run._r) 
# 获取当前工作目录( cwd )
cwd = os.getcwd()
# 读取JSON文件并获取排序信息
def get_order_from_json(json_path):# 读取 JSON 文件,获取文件列表with open(json_path, 'r', encoding='utf-8') as f:data = json.load(f)return [os.path.join(cwd, 'Word_Test', file_name) for file_name in data['file_order']]
# 调用函数读取排序信息
json_path = 'Sort.json'  #JSON文件路径
ordered_files = get_order_from_json(json_path)# 使用排序后的文件列表进行合并
def combine_all_docx_ordered(filename_master, files_list_ordered):# 确保文件列表不为空if not files_list_ordered:print("没有文档可供合并。")returntry:master = Document(filename_master) remove_hyperlinks(master)  except Exception as e:print(f"无法打开主文档{filename_master}{e}")return# 在循环之前添加一个分页符,合并后的文档从第二页开始。master.add_page_break()  composer = Composer(master)# 如果文件列表中只有一个文件,即主文档自身,直接保存即可if len(files_list_ordered) == 1:print("只有一个文档,无需合并。")master.save("single_doc.docx")returnfor doc_temp_path in files_list_ordered[1:]:  try:doc_temp = Document(doc_temp_path)  remove_hyperlinks(doc_temp) except Exception as e:print(f"无法打开文档 {doc_temp_path}:{e}")continuedoc_temp.add_page_break() composer.append(doc_temp) # 保存合并后的文档try:composer.save("sorted_按章节顺序.docx")print("合并后的文档已保存。")except Exception as e:print(f"保存合并文档时出错: {e}")# 验证JSON中的文件是否存在
def verify_files_existence(files_paths):existing_files = []missing_files = []for file_path in files_paths:if os.path.exists(file_path):existing_files.append(file_path)else:missing_files.append(file_path)return existing_files, missing_files
# 验证文件并处理不存在的文件
existing_files, missing_files = verify_files_existence(ordered_files)if missing_files:print("以下文件在JSON中指定但未找到:")for missing_file in missing_files:print(missing_file)
else:# 合并文档# 调用新的函数进行合并combine_all_docx_ordered(ordered_files[0], ordered_files)print("————按JSON排序合并完成————")

创建 Sort.json 文件,其中按自定义顺序存储需合并的 Word 文档名称。
运行脚本后,程序将按 JSON 定义的顺序自动合并文档。

http://www.dtcms.com/wzjs/371647.html

相关文章:

  • 做商城网站哪家好百度百科词条创建入口
  • 营销型网站建设明细报价表什么推广软件效果好
  • 做网站 需要什么样的服务器冯耀宗seo教程
  • 国务院政府网站建设指引优化设计答案五年级下册
  • 南京商城网站建设外贸网站seo推广教程
  • 韩国跨境电商有哪些平台无锡seo公司
  • iis怎么做ip网站吗夫唯seo怎么样
  • 平安保险网站深圳知名seo公司
  • 网站建设跑业务百度最新人工智能
  • 创新的沈阳网站建设苏州旺道seo
  • wordpress下载站地推接单正规平台
  • 宁乡网站建设网站推广入口
  • 怎么做淘宝客网站和APP怎么自己做一个网页
  • 做微信营销网站建设查域名网站
  • 濮阳做网站的公司关键词排名优化提升培训
  • vscode 网站开发精准推广引流5000客源
  • 企业网站建设管理视频武汉seo优化顾问
  • 泊头网站建设的有哪些信阳百度推广公司电话
  • 杭州市上城区建设局网站怎么发布信息到百度
  • 做网上贸易哪个网站好友情链接的作用大不大
  • 六安网站制作公司排名市场营销策划方案模板
  • 丹东网站建免费网站免费
  • flash美食网站论文免费制作网页平台
  • 搭建网站服务器多少钱深圳推广不动产可视化查询
  • 有没有在线辅导家做的网站手机制作网站的软件
  • 免费响应式网站模板seo技术介绍
  • 深圳网站建设服务便宜模板建站价格
  • 建设工程协会网站查询北京知名seo公司精准互联
  • 厦门帮忙建设网站在线客服
  • 怎么做网站互换链接网站收录服务