一种用Python读取Excel指定位置自动填写Word内容的方法

       简述

        其实就是简单的位置读取锁定,然后把内容格式进行判断,复制过去就行了。要解决的难点也就是理清楚列索引特性、直接操作 Excel 单元格 和使用 pandas 库处理 DataFrame的好处和劣势,对读取数据进一步处理的复杂程度,对复杂Excel情况的考虑程度之类的。

过程

        要实现让不懂代码的人也能简单直接用,虽然说写一个可视化窗口最合适,但是费时间,就直接给一个点击即用的的脚本吧。

准备好运行条件,然后点击就可以开始运行填写了。

代码先是处理Excel,转化成为可以让程序理解的模式,然后就是一步一步根据具体需求对文字进行查找、处理加工,最后替换Word的对应匹配了。

详细内容

  • 替换逻辑

通过在Word中写入固定规则的文本,告诉程序你需要Excel哪个位置的的数据内容,然后程序根据固定文本规则,去查找填数。

需要告诉去哪个表,哪个列的内容,哪个行的内容去找,用中文逗号分割‘,’每一个列内容,用中文分号‘;’分割列内容和行。

1、只提供数字+百分比——[表]【列内容,列内容...;对应行】

        环比数值的查找——*环比*[表]{{列内容,列内容...;对应行}}

2、只提供对环比类型的查找

        排名前三的查找——*前三*[表]{{列内容,列内容...;对应行}}

3、只提供对需要查找前三个省份的查找。遇到排名一致的省份,会选取第一个出现的省份。

        排名后三的查找——*后三*[表]{{列内容,列内容...;对应行}}

只提供对需要查找后三个省份的查找。遇到排名一致的省份,会选取第一个出现的省份。

具体代码过程有空再细讲吧

完整代码

import os
import sys
import tkinter as tk
from tkinter import messagebox
import docx
import re
from docx import Document
from docx.shared import Pt
import pandas as pd
import openpyxl
from openpyxl import load_workbook
from openpyxl.utils import get_column_letter


def chuli():
    # 获取  文件所在的目录
    if getattr(sys, 'frozen', False):
        # 如果是运行在一个打包的程序中,使用当前工作目录
        path = os.getcwd()
    else:
        # 否则,使用脚本所在目录
        path = os.path.dirname(os.path.abspath(__file__))
    #print("目录",path)
    files = os.listdir(path)
    #print("目录",files)
    #word_files = [f for f in files if f.lower().endswith('.docx')]
    word_files = [f for f in files if f.lower().endswith(('.docx', '.doc'))]
    #excel_files = [f for f in files if f.lower().endswith('.xlsx')]
    excel_files = [f for f in files if f.lower().endswith(('.xlsx', '.xlx'))]
    #print("路径s",word_files)
    # 将文件名转换为文件路径字符串
    word_path2 = [os.path.join(path, f) for f in word_files]
    excel_path2 = [os.path.join(path, f) for f in excel_files]
    #print("路径2",word_path2)
    # 将路径中的反斜杠替换为斜杠
    # word_path2 = str([word_path1[i].replace('\\', '/') for i in range(len(word_path1))])
    # excel_path2 = str([excel_path1[i].replace('\\', '/') for i in range(len(excel_path1))])

    word_path = ' '.join(word_path2).replace(' ', '')
    excel_path = ' '.join(excel_path2).replace(' ', '')
    #print("路径",word_path)

    # 检查文件数量
    if len(word_files) != 1 or len(excel_files) != 1:
        root = tk.Tk()
        root.withdraw()  # 隐藏主窗口
        if len(word_files) != 1:
            messagebox.showinfo("提示", "请放置唯一一份Word文档")
        if len(excel_files) != 1:
            messagebox.showinfo("提示", "请放置唯一一份Excel文档")
        return
    else:
        # 检查文件名是否包含'修改版'
        if any("修改版" in file for file in word_files + excel_files):
            root = tk.Tk()
            root.withdraw()
            messagebox.showinfo("提示", "请放置原版Excel/Word文档")
            return

    # 文件检查通过,开始执行其他代码
    # ...
    # 您的其他代码放在这里
# 这个是拆分Excel表头的
    # 获取完整的文件路径
    excel_file_path = os.path.join(path, excel_files[0])

    # 加载工作簿
    wb = openpyxl.load_workbook(excel_file_path)

    # 遍历每个工作表
    for sheet in wb.worksheets:
        # 选择当前工作表
        sheet = wb[sheet.title]

        # 遍历行
        for row in sheet.iter_rows():
            # 遍历列
            for cell in row:
                # 检查单元格是否已经合并
                for range_ in list(sheet.merged_cells.ranges):
                    if cell.coordinate in range_:
                        print(f"Cell {cell.coordinate} is merged")
                        # 保存合并单元格的值
                        merged_value = cell.value
                        # 保存合并单元格的范围
                        merged_range = range_
                        # 拆分合并的单元格
                        sheet.unmerge_cells(str(range_))
                        # 将原先的值填充到拆分后的所有单元格
                        for row in sheet[range_.coord]:
                            for cell in row:
                                cell.value = merged_value

        # 插入新的一行在顶部
        sheet.insert_rows(1)

        # 复制原始第一行(现在是第二行)到新的第一行
        for cell in sheet[2]:
            new_cell = sheet.cell(row=1, column=cell.col_idx, value=cell.value)
    excel_path = f"{os.path.splitext(excel_file_path)[0]} 修改版.xlsx"
    # 保存工作簿到指定路径(这里假设路径与原文件相同)
    wb.save(excel_path)


    # 打印word_path和新的excel_path的路径
    #print("Word文件路径:", word_path)
    #print("修改版Excel文件路径:", new_excel_path)

    #return True
    return word_path, excel_path

# 定义第一个代码脚本的函数
def script_one(word_path, excel_path):
    # ...(第一个代码的全部内容)
    # 用相同的方式将第一个代码的所有内容放在这个函数里
    # 最后,返回一个标识执行结果的值,比如True或False
    # 工作开始
    # 功能函数--百分比
    def extract_word_content(word_path):
        """
        从指定路径的Word文档中提取特定格式的内容。

        参数:
        word_path: Word文档的路径。

        返回:
        biao: []中的内容,作为锁定目标sheet的关键字。
        lie: {{}}中分号左边的内容,作为列竖向查询的关键字列表。
        shenfen: {{}}中分号右边的内容,作为行横向查询的关键字。G:/AAA/ces/111.docx
        """
        doc = docx.Document(word_path)
        # print("路径", word_path)
        matches = []  # 用于存储所有匹配项
        # 遍历文档中的每个段落
        for para in doc.paragraphs:
            # 使用正则表达式匹配[]和{{}}中的内容,找到锁定单元格所需的列和行关键字
            all_matches = re.findall(r'\[(.*?)\]\【(.*?)\】', para.text)
            for match in all_matches:
                biao = match[0]
                lie_content, shenfen = match[1].split(';')
                lie = lie_content.split(',')
                matches.append((biao, lie, shenfen, para)) # 将匹配的内容添加到列表中
                # return biao, lie, shenfen
        return matches  # 返回包含所有匹配项的列表
        # print("找到的表什么的",biao)

        # 如果未找到匹配的内容,返回None
        return None, None, None

    def quzhi(biao, lie, shenfen, excel_path):
        # .
        xls = pd.ExcelFile(excel_path)
        if biao in xls.sheet_names:
            df = xls.parse(biao)
            for column_index in df.columns:
                if all(any(df[column_index].iloc[:4].eq(item)) for item in lie):
                    print(f"在工作表 '{biao}' 的列 '{column_index}' 中找到了所有匹配项")

                    # 在找到的列中继续查找基于 shenfen 的行
                    #row_index = df[column_index][4:].eq(shenfen).idxmax()
                    row_index = df.iloc[:, 0].eq(shenfen).idxmax()

                    zhi = df.loc[row_index, column_index]

                    print("找到的行", row_index)
                    print("输出的zhi", zhi)
                    return zhi  # 返回找到的值

            print(f"在工作表 '{biao}' 中未找到包含所有项的列")
        else:
            print(f"未找到工作表: {biao}")

        return None

    # 替换函数
    def process_documents(word_path, excel_path):
        matches = extract_word_content(word_path)
        if not matches:
            print("没有找到匹配的内容")
            return False

        doc = docx.Document(word_path)

        for biao, lie, shenfen, para in matches:
            # 为当前匹配项生成一个特定的正则表达式
            specific_pattern = re.compile(
                r'\[' + re.escape(biao) + r'\]'r'【' + ','.join(re.escape(item) for item in lie) + r';' + re.escape(
                    shenfen) + r'】')
            # print(f"当前的匹配111: {specific_pattern.pattern}")
            zhi = quzhi(biao, lie, shenfen, excel_path)
            if zhi is None:
                continue

            for para in doc.paragraphs:
                full_text = ''.join([run.text for run in para.runs])
                # print(f"当前的匹配full_text: {full_text}")
                match = specific_pattern.search(full_text)
                # print(f"当前的匹配——————: {match}")

                if match:
                    # 判断是否需要将zhi乘以100
                    if zhi < 1:  # 如果zhi是小于1的小数,则认为它是一个百分比,需要乘以100
                        formatted_zhi = '{:.2f}%'.format(zhi * 100)
                    else:  # 否则,zhi已经是百分比形式,直接格式化
                        formatted_zhi = '{:.2f}%'.format(zhi)
                    updated_text = specific_pattern.sub(formatted_zhi, full_text)

                    # print(f"当前的匹配updated_text——————: {updated_text}")
                    for run in para.runs:
                        run.clear()
                    para.runs[0].text = updated_text
                    para.runs[0].font.name = '仿宋_GB2312'
                    para.runs[0].font.size = Pt(16)

        #new_name = f"{os.path.splitext(word_path)[0]} 修改版.docx"
        doc.save(word_path)
        #print("文档处理完成,保存为:", new_name)
        return True
    return process_documents(word_path, excel_path)  # 返回process_documents函数

# 定义第二个代码脚本的函数
def script_two(word_path, excel_path):
    # ...(第二个代码的全部内容)
    # 用相同的方式将第二个代码的所有内容放在这个函数里
    # 最后,返回一个标识执行结果的值,比如True或False
    # 功能函数--环比
    def extract_word_content1(word_path):
        doc = docx.Document(word_path)
        # print("路径", word_path)
        matches1 = []  # 用于存储所有匹配项
        # 遍历文档中的每个段落
        for para in doc.paragraphs:
            # 使用正则表达式匹配[]和{{}}中的内容,找到锁定单元格所需的列和行关键字
            all_matches1 = re.findall(r'(\*环比\*)\[(.*?)\]\{\{(.*?)\}\}', para.text)
            for match1 in all_matches1:
                biao1 = match1[1]
                lie_content1, shenfen1 = match1[2].split(';')
                lie1 = lie_content1.split(',')
                matches1.append((biao1, lie1, shenfen1, para))  # 将匹配的内容添加到列表中
                # return biao1, lie1, shenfen1
        return matches1  # 返回包含所有匹配项的列表
        # print("找到的表什么的",biao)

        # 如果未找到匹配的内容,返回None
        return None, None, None

    def huanbi(biao1, lie1, shenfen1, excel_path):
        wb = load_workbook(excel_path, data_only=True)
        sheet = wb[biao1]
        if not sheet:
            return []  # 如果工作表不存在,返回空列表

        # 为了找到包含lie1中所有元素的列
        col_letter = None
        for col_index, col in enumerate(sheet.iter_cols(min_row=1, values_only=True), start=1):
            if all(item in col for item in lie1):
                col_letter = get_column_letter(col_index)
                break

        if col_letter:
            # 在找到的列中寻找shenfen1对应的行
            for row_index, row in enumerate(sheet.iter_rows(min_row=1, values_only=True), start=1):
                if row[0] == shenfen1:
                    zhi1 = sheet[col_letter + str(row_index)].value
                    cell_format = sheet[col_letter + str(row_index)].number_format
                    if zhi1 is None:
                        continue
                    try:
                        numeric_zhi1 = float(zhi1)
                    except ValueError:
                        continue

                    # 新增判断逻辑
                    if numeric_zhi1 == 0.00:
                        ss = "与上个月持平"
                    else:
                        prefix = "环比上升" if numeric_zhi1 > 0 else "环比下降"
                        #formatted_numeric_zhi1 = abs(numeric_zhi1) if prefix == "下降" else numeric_zhi1
                        formatted_numeric_zhi1 = abs(numeric_zhi1) if numeric_zhi1 < 0 else numeric_zhi1 # 这里做了修改
                        # 根据单元格格式进行格式化
                        if cell_format == '#,##0.00_ ':
                            formatted_zhi1 = '{:.2f}%'.format(formatted_numeric_zhi1)
                        elif cell_format == '0.00%':
                            formatted_zhi1 = '{:.2f}%'.format(formatted_numeric_zhi1 * 100)
                        else:
                            formatted_zhi1 = str(formatted_numeric_zhi1)+ "%"
                        ss = "{}{}".format(prefix, formatted_zhi1)
                    print("找到的zhi1", ss)
                    return ss

        #return None, None, None

    # 替换函数
    def process_documents1(word_path, excel_path):
        # 处理第二部分 - 提取信息并返回结果

        matches1 = extract_word_content1(word_path)
        if not matches1:
            print("没有找到匹配的内容")
            return False

        doc = docx.Document(word_path)
        #wb = load_workbook(excel_path)  # 加载Excel工作簿

        for biao1, lie1, shenfen1, para in matches1:
            specific_pattern1 = re.compile(
                r'(\*环比\*)\[' + re.escape(biao1) + r'\]'r'\{\{' + ','.join(
                    re.escape(item) for item in lie1) + r';' + re.escape(shenfen1) + r'\}\}')

            #zhi1, cell_format = huanbi(biao1, lie1, shenfen1, para, excel_path)
            # 从 huanbi 获取返回值
            ss = huanbi(biao1, lie1, shenfen1, excel_path)
            if ss is None:
                continue

            for para in doc.paragraphs:
                full_text = ''.join([run.text for run in para.runs])
                #full_text = para.text
                match1 = specific_pattern1.search(full_text)
                if match1:
                    updated_text = specific_pattern1.sub(ss, full_text)
                    #para.text = updated_text
                    for run in para.runs:
                        run.clear()
                    para.runs[0].text = updated_text
                    para.runs[0].font.name = '仿宋_GB2312'
                    para.runs[0].font.size = Pt(16)

        #new_name = f"{os.path.splitext(word_path)[0]} .docx"
        doc.save(word_path)
        return True
    return process_documents1(word_path, excel_path)  # 返回process_documents1函数

# 定义第三个代码脚本的函数
def script_three(word_path, excel_path):
    #功能函数 - -前三
    def extract_word_content2(word_path):
        doc = docx.Document(word_path)
        # print("路径", word_path)
        matches2 = []  # 用于存储所有匹配项
        # 遍历文档中的每个段落
        for para in doc.paragraphs:
            # 使用正则表达式匹配[]和{{}}中的内容,找到锁
            # 定单元格所需的列和行关键字
            match2 = re.findall(r'(\*前三\*)\[(.*?)\]\{\{(.*?)\}\}', para.text)
            for match2 in match2:
                # panduan = match2.group(1).strip('*')
                biao2 = match2[1]
                lie_content2 = match2[2]
                lie2 = lie_content2.split(',')
                matches2.append((biao2, lie2, para))  # 将匹配的内容添加到列表中
                # return biao2, lie2
        print("找到的匹配", matches2)
        return matches2  # 返回包含所有匹配项的列表

        # 如果未找到匹配的内容,返回None
        return None, None, None


    def qiansan(biao2, lie2, excel_path):
        wb = load_workbook(excel_path, data_only=True)
        sheet = wb[biao2]

        results2 = []

        # 为了找到包含lie2中所有元素的列
        col_letter = None
        for col_index, col in enumerate(sheet.iter_cols(min_row=1, values_only=True), start=1):
            if all(item in col for item in lie2):
                col_letter = get_column_letter(col_index)
                print(f"在工作表 '{biao2}' 的列 '{col_letter}' 中找到了所有匹配项")
                break

        if col_letter:
            # 将列字母转换为列的索引号
            col_index = openpyxl.utils.cell.column_index_from_string(col_letter) - 1

            # 在找到的列中寻找1, 2, 3对应的行
            for i in range(1, 4):
                for row_index, row in enumerate(sheet.iter_rows(min_row=1, values_only=True), start=1):
                    cell_value = row[col_index]
                    if isinstance(cell_value, int) and cell_value == i:
                        # 找到对应的行号
                        # print(f"在 '{col_letter}' 列中找到值为 {i} 的行号为: {row_index}")

                        # 获取并格式化该行前一列的指定单元格的值
                        prev_col_letter = get_column_letter(col_index - 0)
                        zhi2 = sheet[prev_col_letter + str(row_index)].value
                        try:
                            zhi2 = float(zhi2)
                        except ValueError:
                            print(f"无法将单元格 {prev_col_letter}{row_index} 的值转换为浮点数: {zhi2}")
                            # 这里你可以选择如何处理错误,比如设置一个默认值或者跳过当前操作
                        cell_format = sheet[col_letter + str(row_index)].number_format
                        print(f"找到的格式为 : {cell_format}")

                        # 根据单元格格式进行格式化
                        if zhi2 < 1:  # 如果zhi是小于1的小数,则认为它是一个百分比,需要乘以100
                            formatted_zhi2 = '{:.2f}%'.format(zhi2 * 100)
                        elif zhi2 > 1:
                            formatted_zhi2 = '{:.2f}%'.format(zhi2)
                        else:
                            formatted_zhi2 = str(zhi2)

                        s = sheet['A' + str(row_index)].value  # 假设第一列是省份
                        zhi_str = "{}({})".format(s, formatted_zhi2)
                        results2.append(zhi_str)
                        break

            print(results2)
            return results2

        print(f"在工作表 '{biao2}' 中未找到包含所有项的列")
        return []


    '''
                        # 根据单元格格式进行格式化----返回的都是General没办法啊
                        if cell_format == '#,##0.00_ ':
                            formatted_zhi2 = '{:.2f}%'.format(zhi2)
                        elif cell_format == '0.00%':
                            formatted_zhi2 = '{:.2f}%'.format(zhi2 * 100)
                        else:
                            formatted_zhi2 = str(zhi2)
    '''


    # 替换函数
    def process_documents2(word_path, excel_path):
        # 处理第三部分 - 提取信息并返回结果

        matches2 = extract_word_content2(word_path)
        if not matches2:
            print("没有找到匹配的内容")
            return False

        doc = docx.Document(word_path)
        wb = load_workbook(excel_path)  # 加载Excel工作簿

        for biao2, lie2, para in matches2:
            # specific_pattern2 = re.compile(
            # r'(\*前三\*)\[' + re.escape(biao2) + r'\]'r'\{\{' + ','.join(re.escape(item) for item in lie2) + r';' +  r'\}\}')
            specific_pattern2 = re.compile(
                r'\*前三\*\[' + re.escape(biao2) + r'\]\{\{' + ','.join(re.escape(item) for item in lie2) + r'\}\}'
            )

            print(f"找到的匹配文本: {specific_pattern2}")
            results2 = qiansan(biao2, lie2, excel_path)
            if results2 is None:
                continue
            # 将结果列表转换为字符串
            results_str = ', '.join(results2)
            for para in doc.paragraphs:
                full_text = ''.join([run.text for run in para.runs])
                match2 = specific_pattern2.search(full_text)
                if match2:
                    updated_text = specific_pattern2.sub(results_str, full_text)
                    for run in para.runs:
                        run.clear()
                    para.runs[0].text = updated_text
                    para.runs[0].font.name = '仿宋_GB2312'
                    para.runs[0].font.size = Pt(16)

        #new_name = f"{os.path.splitext(word_path)[0]} .docx"
        doc.save(word_path)
        return True
    return process_documents2(word_path, excel_path)  # 返回process_documents2函数

# 定义第四个代码脚本的函数
def script_four(word_path, excel_path):
    # 功能函数--后三
    def extract_word_content2(word_path):
        doc = docx.Document(word_path)
        # print("路径", word_path)
        matches2 = []  # 用于存储所有匹配项
        # 遍历文档中的每个段落
        for para in doc.paragraphs:
            # 使用正则表达式匹配[]和{{}}中的内容,找到锁
            # 定单元格所需的列和行关键字
            match2 = re.findall(r'(\*后三\*)\[(.*?)\]\{\{(.*?)\}\}', para.text)
            for match2 in match2:
                # panduan = match2.group(1).strip('*')
                biao2 = match2[1]
                lie_content2 = match2[2]
                lie2 = lie_content2.split(',')
                matches2.append((biao2, lie2, para))  # 将匹配的内容添加到列表中
            # return biao2, lie2
        print("找到的匹配", matches2)
        return matches2  # 返回包含所有匹配项的列表

        # 如果未找到匹配的内容,返回None
        return None, None, None

    def hosan(biao2, lie2, excel_path):
        wb = load_workbook(excel_path, data_only=True)
        # sheet = wb[biao2]
        matches2 = extract_word_content2(word_path)
        results3 = []  # 用于存储所有匹配项
        # 找到对应的列
        xls = pd.ExcelFile(excel_path)
        if biao2 in xls.sheet_names:
            df = xls.parse(biao2)
        #for biao2, lie2 in matches2:
            # print(biao2, lie2)
            if biao2 in xls.sheet_names:
                df = xls.parse(biao2)
                for column_index in df.columns:
                    if all(any(df[column_index].iloc[:4].eq(item)) for item in lie2):
                        print(f"在工作表 '{biao2}' 的列 '{column_index}' 中找到了所有匹配项")
                        # print(f"没有找到包含 '{lie2}' 的列")
                        # 选择正确的数据列
                        column_data = df[column_index]

                        # 将列中的内容转换为数字,忽略无法转换的部分
                        numeric_values = pd.to_numeric(column_data, errors='coerce')
                        # print("转换为数值后的列:", numeric_values)

                        # 删除包含 NaN 的行
                        # numeric_values = numeric_values.dropna()

                        # 找到最大的三个数字
                        top_3_indices = numeric_values.nlargest(3).index

                        for i, row_index in enumerate(top_3_indices, start=1):
                            # 获取前一列的值
                            zhi3 = df.iloc[row_index, df.columns.get_loc(column_index) - 1]
                            print(f"直接找到的zhi3 '{zhi3}' ")
                            # 根据单元格格式进行格式化
                            if zhi3 < 1:  # 如果zhi是小于1的小数,则认为它是一个百分比,需要乘以100
                                formatted_zhi3 = '{:.2f}%'.format(zhi3 * 100)
                            elif zhi3 > 1:
                                formatted_zhi3 = '{:.2f}%'.format(zhi3)
                            else:
                                formatted_zhi3 = str(zhi3)
                            print(f"格式化后的formatted_zhi3 '{formatted_zhi3}' ")
                            s = df.iloc[row_index, 0]  # 对应获取省份
                            zhi_str = "{}({})".format(s, formatted_zhi3)  # 格式化字符串
                            results3.append(zhi_str)

                        if not results3:
                            print(f"在工作表 '{biao2}' 中未找到包含所有项的列")
                            return []
                        print(f"找到的后三 '{results3}' ")
                        return results3

    # 替换函数
    def process_documents3(word_path, excel_path):
        # 处理第三部分 - 提取信息并返回结果

        matches2 = extract_word_content2(word_path)
        if not matches2:
            print("没有找到匹配的内容")
            return False

        doc = docx.Document(word_path)
        wb = load_workbook(excel_path)  # 加载Excel工作簿

        for biao2, lie2, para in matches2:
            # specific_pattern2 = re.compile(
            # r'(\*前三\*)\[' + re.escape(biao2) + r'\]'r'\{\{' + ','.join(re.escape(item) for item in lie2) + r';' +  r'\}\}')
            specific_pattern2 = re.compile(
                r'\*后三\*\[' + re.escape(biao2) + r'\]\{\{' + ','.join(re.escape(item) for item in lie2) + r'\}\}'
            )

            print(f"找到的匹配文本: {specific_pattern2}")
            results3 = hosan(biao2, lie2, excel_path)
            if results3 is None:
                continue
            # 将结果列表转换为字符串
            results_str = ', '.join(results3)
            for para in doc.paragraphs:
                full_text = ''.join([run.text for run in para.runs])
                match2 = specific_pattern2.search(full_text)
                if match2:
                    updated_text = specific_pattern2.sub(results_str, full_text)
                    for run in para.runs:
                        run.clear()
                    para.runs[0].text = updated_text
                    para.runs[0].font.name = '仿宋_GB2312'
                    para.runs[0].font.size = Pt(16)

        #new_name = f"{os.path.splitext(word_path)[0]} 修改版.docx"
        doc.save(word_path)
        #print("文档处理完成,保存为:", new_name)
        return True
    return process_documents3(word_path, excel_path)  # 返回process_documents2函数

# 主程序
def main():
    word_path, excel_path = chuli()
    process_documents = script_one(word_path, excel_path)
    if not process_documents:
        print("第一个脚本执行失败")
        return

    process_documents2 = script_three(word_path, excel_path)
    if not process_documents2:
        print("第三个脚本执行失败")
        return
    process_documents3 = script_four(word_path, excel_path)
    if not process_documents3:
        print("第四个脚本执行失败")
        return

    process_documents1 = script_two(word_path, excel_path)
    if not process_documents1:
        print("第二个脚本执行失败")
        return

    print("四个脚本均已成功执行")

if __name__ == "__main__":
    main()





  • 11
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值