技能 libreoffice-writer
📄

libreoffice-writer

低風險 ⚙️ 外部命令📁 檔案系統存取🔑 環境變數⚡ 包含腳本

自動化 LibreOffice Writer 文件

手動編輯文件耗時且容易出錯。此技能透過 UNO 整合自動化 LibreOffice Writer 操作,實現程式化文件建立、編輯、格式化及匯出。

支援: Claude Codex Code(CC)
🥉 74 青銅
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「libreoffice-writer」。 Create a new document with a title and export to PDF

預期結果:

  • Document created successfully: /path/to/report.odt
  • Exported to PDF: /path/to/report.pdf

正在使用「libreoffice-writer」。 Find and format text in existing document

預期結果:

  • Opened document: /path/to/draft.odt
  • Formatted text range: bold, center-aligned
  • Changes saved and document closed

正在使用「libreoffice-writer」。 Apply patch with multiple operations

預期結果:

  • Patch parsed: 3 operations
  • Operation 1 (replace_text): success
  • Operation 2 (format_text): success
  • Operation 3 (insert_table): success
  • Overall status: ok
  • Document persisted: true

安全審計

低風險
v2 • 3/19/2026

Static analysis flagged 175 patterns but evaluation confirms these are false positives. The skill legitimately uses subprocess to launch LibreOffice with hardcoded arguments, tempfile for secure temp directories, and importlib for module detection. All external command usage has no user input injection vectors. Risk is low due to filesystem and external command dependencies requiring LibreOffice installation.

14
已掃描檔案
2,550
分析行數
7
發現項
2
審計總數
低風險問題 (3)
External Process Execution
subprocess.Popen launches LibreOffice soffice binary. All arguments are hardcoded strings with no user input injection. This is legitimate automation of installed software.
Temporary Directory Creation
Uses tempfile.mkdtemp() to create isolated profile directories for LibreOffice instances. Directories are cleaned up in finally blocks.
Environment Variable Access
Reads LIBREOFFICE_PROGRAM_PATH environment variable to locate UNO module. Value is used only for path resolution, not executed.
審計者: claude 查看審計歷史 →

品質評分

64
架構
100
可維護性
87
內容
24
社群
84
安全
91
規範符合性

你能建構什麼

自動化報告生成

透過建立文件、插入格式化文字和表格,然後匯出至 PDF 進行分發,生成標準化報告。

文件範本處理

載入範本文件,使用動態內容替換預留位置文字,使用新資料更新表格,並匯出自訂版本。

批次文件作業

使用具有失敗時原子性回滾的修補程式工作流程,對多個文件套用一致的格式變更。

試試這些提示

建立並填充文件
在 /path/to/report.odt 建立新的 LibreOffice Writer 文件。插入標題「Monthly Report」,新增區段標題「Summary」,然後插入描述本月成就的段落。將最終文件匯出為 PDF。
使用結構化定位編輯
開啟 /path/to/draft.odt 並找到出現在「Financial Overview」之後且在「Next Steps」之前的句子「Quarterly revenue grew significantly」。將其設為粗體並置中對齊。然後在「Action Items」之後插入一個包含三個任務的項目符號列表:Review budget、Schedule meeting、Send updates。
使用資料的表格作業
開啟 /path/to/data-report.odt 中的文件。插入一個名為「Sales Data」的 4 列 3 欄表格。使用標題 [Region, Q1, Q2] 和 North、South、East 區域的資料列填充表格。日後有新數字時更新 Q2 值。
原子性修補程式工作流程
在原子模式下對 /path/to/manuscript.odt 套用此修補程式:首先,將所有「Draft」替換為「Final」。其次,將章節標題格式化為 14pt 粗體。第三,插入目錄。如果任何作業失敗,回滾所有變更並報告錯誤。

最佳實務

  • 使用 UNO 型 Writer API 時務必使用絕對檔案路徑
  • 使用完整句子或段落層級片語作為錨點文字目標,而非單一單詞
  • 當相同文字可能多次出現時,使用 after 和 before 邊界來限制搜尋範圍
  • 將會話作業包裝在 try/finally 或內容管理員中以確保正確清理
  • 在切換到原子模式用於生產環境之前,先在 best_effort 模式下測試修補程式工作流程

避免

  • 使用相對路徑 - UNO 需要所有文件作業使用絕對檔案路徑
  • 當相同文字在文件中多次出現時省略 occurrence 參數
  • 在 session.close() 被呼叫後繼續呼叫會話方法
  • 在修補程式項目或資料欄位中提供格式錯誤的 JSON
  • 期望段落對齊僅套用於相符文字而非整個段落

常見問題

為什麼此技能需要安裝 LibreOffice?
此技能使用 LibreOffice 的 UNO(通用網路物件)API 與 Writer 文件互動。UNO 是 LibreOffice 的原生自動化介面,需要本機安裝的 LibreOffice 及其 Python UNO 繫結。
我可以匯出哪些檔案格式?
此技能支援直接匯出為 PDF 和 DOCX 格式。根據您的 LibreOffice 安裝和篩選器可用性,可能提供其他格式。
如何修正「ModuleNotFoundError: No module named uno」?
將系統的 LibreOffice Python 路徑新增至 PYTHONPATH。在 Linux 上,這通常是 /usr/lib/python3/dist-packages。將 PYTHONPATH 設為同時包含技能指令碼目錄和 LibreOffice Python 模組。
原子模式和 best_effort 修補程式模式之間有什麼差異?
原子模式會在第一個失敗時停止,重設會話,且不保存任何內容。best_effort 模式會繼續執行所有作業並記錄哪些成功,即使某些作業失敗也會保存成功的變更。
我可以編輯目前在 LibreOffice 中開啟的文件嗎?
不行。文件應在透過 UNO 編輯之前關閉。嘗試開啟已被另一個 LibreOffice 執行個體鎖定的文件將會失敗或導致衝突。
當相同片語出現多次時,如何定位特定文字?
使用 occurrence 欄位指定要目標的相符項目(從零開始索引),或新增 after 和 before 邊界將搜尋範圍縮小到文件的特定區段。