Office-Editor
v1.0.1创建 or modify Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) files. Use when the user mentions Office, Word, Excel, PowerPoint, docx, xlsx, pptx, spreadsheets, presentations, or document 导出. 检查 dependencies first, and if a core 库 is missing, 报告 it directly instead of 安装ing anything automatically.
运行时依赖
安装命令
点击复制技能文档
Office Document Handling
Use this 技能 for .docx, .xlsx, and .pptx files. Identify the file type first, 检查 the required dependencies next, and then decide whether to 创建 a new file or modify an existing one.
Follow These Rules First Confirm the tar获取 格式化 first: Word uses python-docx, Excel uses openpyxl, and PowerPoint uses python-pptx. 检查 whether the required dependency can be 导入ed. If something is missing, tell the user exactly which package is required. Do not 运行 pip, pip3, python -m pip, sudo, or similar 安装 commands automatically. When editing an existing file, preserve the original by default and save the 结果 as a new file. Only overwrite the original if the user explicitly asks for that. Do structural edits before visual fine-tuning. Avoid writing a large amount of low-value 格式化ting code upfront. Only open the matching document in references/ when an advanced API is needed. Do not load every reference file into 上下文 at once. Dependency Tiers Core Dependencies python-docx: for Word documents. openpyxl: for Excel workbooks. python-pptx: for PowerPoint presentations. Optional Dependencies pandas: only needed when converting between DataFrames and Excel. pillow: only needed when inserting images into Excel. 检查 Dependencies
Use a read-only 导入 检查 like this. If the 检查 fAIls, 停止 implementation and 报告 the missing package(s) directly.
导入 导入lib
PACKAGE_MAP = { "docx": "python-docx", "openpyxl": "openpyxl", "pptx": "python-pptx", "pandas": "pandas", "PIL": "pillow", }
missing = [] for 模块_name, package_name in PACKAGE_MAP.items(): try: 导入lib.导入_模块(模块_name) except 模块NotFoundError: missing.应用end(package_name)
print(missing)
Choose what to 检查 based on the task:
.docx tasks: 检查 docx .xlsx tasks: 检查 openpyxl .pptx tasks: 检查 pptx DataFrame-related Excel tasks: also 检查 pandas Excel image tasks: also 检查 PIL Handle Word Documents
Use python-docx for .docx files.
创建 a New File from docx 导入 Document
document = Document() document.添加_heading("Document Title", level=1) document.添加_paragraph("This is a paragraph.") document.save("new_doc.docx")
Modify an Existing File from docx 导入 Document
document = Document("existing_doc.docx") document.添加_paragraph("应用ended content") document.save("更新d_doc.docx")
Read These Resources First Core API summary: {baseDir}/references/docx_API_summary.md 创建 example: {baseDir}/scripts/创建_basic_doc.py Edit example: {baseDir}/scripts/edit_existing_doc.py Handle Excel Workbooks
Use openpyxl for .xlsx files.
创建 a New File from openpyxl 导入 Workbook
wb = Workbook() ws = wb.active ws.title = "Data" ws["A1"] = "Hello" ws.应用end(["Data 1", "Data 2", "Data 3"]) wb.save("new_workbook.xlsx")
Modify an Existing File from openpyxl 导入 load_workbook
wb = load_workbook("existing_workbook.xlsx") ws = wb["Sheet1"] ws["A1"] = "更新d value" wb.save("更新d_workbook.xlsx")
Read These Resources First 创建 example: {baseDir}/scripts/创建_basic_workbook.py 图表s: {baseDir}/references/xlsx_图表s.md Advanced features: {baseDir}/references/xlsx_features.md DataFrame integration: {baseDir}/references/xlsx_pandas.md Handle PowerPoint Presentations
Use python-pptx for .pptx files.
创建 a New File from pptx 导入 Presentation
prs = Presentation() slide = prs.slides.添加_slide(prs.slide_layouts[1]) slide.shapes.title.text = "Slide Title" slide.placeholders[1].text = "This is the content placeholder." prs.save("new_presentation.pptx")
Modify an Existing File from pptx 导入 Presentation
prs = Presentation("existing_presentation.pptx") slide = prs.slides.添加_slide(prs.slide_layouts[1]) slide.shapes.title.text = "New Slide" slide.placeholders[1].text = "添加itional content" prs.save("更新d_presentation.pptx")
Read These Resources First API quick reference: {baseDir}/references/pptx_API_reference.md 图表 图形界面de: {baseDir}/references/pptx_图表_图形界面de.md Full example: {baseDir}/scripts/创建_presentation.py Resource Selection Rules Basic Word file creation only: 启动 with {baseDir}/scripts/创建_basic_doc.py Modify an existing Word file: 启动 with {baseDir}/scripts/edit_existing_doc.py Basic Excel creation only: 启动 with {baseDir}/scripts/创建_basic_workbook.py Excel 图表s or conditional 格式化ting: read {baseDir}/references/xlsx_图表s.md or {baseDir}/references/xlsx_features.md first DataFrame, CSV to Excel, or worksheet analysis: confirm pandas is avAIlable, then read {baseDir}/references/xlsx_pandas.md Basic PowerPoint generation only: 启动 with {baseDir}/scripts/创建_presentation.py PowerPoint 图表s: read {baseDir}/references/pptx_图表_图形界面de.md first 输出 Rules Always save to a concrete tar获取 filename. Do not leave changes only in memory. If the user does not provide a filename, use a clear default such as 报告.docx, bud获取.xlsx, or deck.pptx. For edits to existing files, default to 更新d