shdskill01

Used to merge multiple Excel workbooks into a new workbook while fully preserving each sheet's formatting, names, column widths, row heights, and merged cells. Suitable for scenarios like data aggregation and report consolidation. Users can select files via a popup or attach files directly in the conversation to perform the merge.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "shdskill01" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-cad7751053d3754ffd51c90882567641aba9848692d268ec2bdd91291d045515. Verify the upstream source and version against https://skillhub.cn/skills/user_9355e276/shdskill01 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Used to merge multiple Excel workbooks into a new workbook while fully preserving each sheet's formatting, names, column widths, row heights, and merged cells. Suitable for scenarios like data aggregation and report consolidation. Users can select files via a popup or attach files directly in the conversation to perform the merge.

0 Downloads

Introduction source: third_party · user_9355e276 · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: shdskill01
description: 多个excel工作簿合并为一个

skill: name: 合并Excel工作簿 description: 将多个Excel工作簿合并为一个新工作簿,完全保留各工作表的格式和名称。支持通过弹窗选择文件或使用对话中已添加的文件。 actions:

  • trigger:

    • 合并工作簿
    • 合并excel工作簿
    • 合并添加的.*个excel工作簿 action: merge_excel_workbooks user_prompt: true parameters:
    • name: file_paths type: array description: 要合并的Excel文件路径列表。如果用户未在对话中添加文件,则触发弹窗让用户选择。 required: true
    • name: save_path type: string description: 合并后新工作簿的保存路径。由用户通过弹窗选择保存位置。 required: true code: | import os import sys import tkinter as tk from tkinter import filedialog, messagebox import openpyxl from openpyxl import load_workbook from openpyxl.utils import get_column_letter import traceback

    def merge_workbooks(file_paths, save_path): """ 合并多个Excel工作簿,完全保留每个工作表的格式和名称。 """ if not file_paths: raise ValueError("未选择任何要合并的文件。")

      # 加载第一个工作簿作为基础
      base_wb = load_workbook(file_paths[0])
    
      # 记录所有工作表名称,避免重复
      sheet_names = set(base_wb.sheetnames)
    
      # 遍历其余工作簿,将工作表添加到基础工作簿中
      for file_path in file_paths[1:]:
          try:
              wb = load_workbook(file_path)
              for sheet_name in wb.sheetnames:
                  # 如果工作表名已存在,则添加后缀
                  new_sheet_name = sheet_name
                  counter = 1
                  while new_sheet_name in sheet_names:
                      new_sheet_name = f"{sheet_name}_{counter}"
                      counter += 1
    
                  # 复制工作表
                  source_sheet = wb[sheet_name]
                  target_sheet = base_wb.create_sheet(new_sheet_name)
    
                  # 复制所有单元格的值和样式
                  for row in source_sheet.iter_rows():
                      for cell in row:
                          new_cell = target_sheet.cell(row=cell.row, column=cell.column)
                          new_cell.value = cell.value
                          if cell.has_style:
                              new_cell.font = cell.font.copy()
                              new_cell.border = cell.border.copy()
                              new_cell.fill = cell.fill.copy()
                              new_cell.number_format = cell.number_format
                              new_cell.protection = cell.protection.copy()
                              new_cell.alignment = cell.alignment.copy()
    
                  # 复制列宽和行高
                  for col in source_sheet.column_dimensions:
                      target_sheet.column_dimensions[col].width = source_sheet.column_dimensions[col].width
                  for row in source_sheet.row_dimensions:
                      target_sheet.row_dimensions[row].height = source_sheet.row_dimensions[row].height
    
                  # 复制合并单元格
                  for merged_range in source_sheet.merged_cells.ranges:
                      target_sheet.merge_cells(str(merged_range))
    
                  sheet_names.add(new_sheet_name)
          except Exception as e:
              raise Exception(f"处理文件 {file_path} 时出错: {str(e)}")
    
      # 保存合并后的工作簿
      try:
          base_wb.save(save_path)
          return f"成功合并 {len(file_paths)} 个工作簿,保存至: {save_path}"
      except Exception as e:
          raise Exception(f"保存文件时出错: {str(e)}")

    def select_files(): """弹出文件选择对话框,让用户选择Excel文件""" root = tk.Tk() root.withdraw() # 隐藏主窗口 file_paths = filedialog.askopenfilenames( title="选择要合并的Excel工作簿", filetypes=[("Excel文件", ".xlsx .xlsm .xltx .xltm"), ("所有文件", ".")] ) return list(file_paths)

    def select_save_path(): """弹出保存对话框,让用户选择保存位置""" root = tk.Tk() root.withdraw() save_path = filedialog.asksaveasfilename( title="保存合并后的工作簿", defaultextension=".xlsx", filetypes=[("Excel工作簿", ".xlsx"), ("Excel启用宏的工作簿", ".xlsm")] ) return save_path

    def main(params): """ 主执行函数,由Work Buddy调用。 params: 包含 file_paths 和 save_path 的字典 """ try:

    获取文件路径列表

          file_paths = params.get('file_paths')
          save_path = params.get('save_path')
    
          # 如果未提供文件路径或为空,则弹出选择对话框
          if not file_paths:
              file_paths = select_files()
              if not file_paths:
                  return "未选择任何文件,操作取消。"
    
          # 如果未提供保存路径,则弹出保存对话框
          if not save_path:
              save_path = select_save_path()
              if not save_path:
                  return "未选择保存位置,操作取消。"
    
          # 执行合并
          result = merge_workbooks(file_paths, save_path)
          messagebox.showinfo("合并完成", result)
          return result
    
      except Exception as e:
          error_msg = f"合并过程中发生错误: {str(e)}\n{traceback.format_exc()}"
          messagebox.showerror("错误", error_msg)
          return error_msg

    如果脚本直接运行,执行主函数(用于测试)

    if name == "main": main({}) dependencies:

    • openpyxl
    • tkinter python_version: ">=3.6" environment: embedded exec_mode: python timeout: 300 retry: 0 output_behavior: text need_upload: true upload_file_types:
    • .xlsx
    • .xlsm
    • .xltx
    • .xltm help: | 此技能用于合并多个Excel工作簿为一个新工作簿,并完全保留所有工作表的格式和名称。

    使用方式:

    1. 在对话中触发关键词“合并工作簿”或“合并excel工作簿”。
    2. 如果已通过“+”号添加了Excel文件,则直接使用这些文件进行合并。
    3. 如果未添加文件,则会自动弹出文件选择对话框,供您浏览并选择要合并的文件。
    4. 随后会弹出保存对话框,让您选择合并后新工作簿的保存位置。

    注意:

    • 合并后的工作簿中,每个工作表将以原工作簿中的工作表名称命名。
    • 如果存在同名工作表,会自动添加数字后缀以区分。
    • 所有单元格的值、样式、列宽、行高和合并单元格都会被完整保留。
    • 无需安装Python环境,Work Buddy内置运行环境。

Current listing version

1.0.0

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

  • 解决多个Excel工作簿合并的实际办公需求,实用性强
  • 支持保留格式、样式、列宽、行高和合并单元格,功能完整
Trigger Precision85/100

Highlights

  • 触发词覆盖合理,能较好匹配用户意图
  • 支持多种变体表达,边界清晰
Structure and Standards92/100

Highlights

  • Phase/步骤清晰,有完整端到端示例
  • frontmatter完整,文档结构规范
Execution Reliability88/100

Highlights

  • 工具来源明确,参数正确
  • 覆盖主要异常场景,有弹窗提示机制
Evidence Verifiability (mean of the first four)86/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Save or modify files

    Confirm the output directory and whether existing files will be replaced. Back up important files and prefer a new output directory.

    Mentioned in main document · lines 93

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.