libreoffice-calc
使用 UNO 自動化 LibreOffice Calc 試算表
手動編輯試算表既繁瑣又容易出錯。此技能透過 UNO API 以程式方式自動化 Calc 操作,實現可靠的批次處理。
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「libreoffice-calc」。 Create spreadsheet, add data to range A0:B2, export to PDF
預期結果:
- Spreadsheet created at /reports/output.ods
- Data written to range Sheet1.A0:B2 (3 cells)
- Exported to PDF: /reports/output.pdf (127 KB)
正在使用「libreoffice-calc」。 Read cell B5 from /data/sales.ods
預期結果:
- Cell Sheet1.B5:
- Value: 4250.00
- Type: number
- Formula: None
正在使用「libreoffice-calc」。 Create bar chart from A0:C10, anchor at row 12
預期結果:
- Chart 'Sales Overview' created on Sheet1
- Data range: A0:C10 (11 rows, 3 columns)
- Position: Row 12, Column 0
- Dimensions: 8000 x 6000 units
安全審計
低風險Static analysis flagged 197 patterns across 13 files. After evaluation, all high-severity findings are false positives: cryptographic warnings misidentified UNO connection code, 'system reconnaissance' flagged exception class definitions, and 'dynamic imports' were standard Python import statements. Shell command patterns exist only in markdown documentation. The single confirmed external command (subprocess.Popen launching LibreOffice) uses hardcoded arguments with no user input injection risk. Temp file usage follows Python best practices with proper cleanup. Skill is safe for publication with minor documentation recommended.
低風險問題 (2)
風險因素
⚙️ 外部命令 (1)
📁 檔案系統存取 (2)
🔑 環境變數 (1)
品質評分
你能建構什麼
自動化財務報告
透過填入資料至範本、套用貨幣格式,並為利害關係人簡報建立趨勢圖表,產生月度營收報告。
大量資料匯出與轉換
將資料從資料庫或 API 擷取至結構化試算表,套用驗證規則,並匯出為多種格式以供散發。
範本式文件生成
使用動態資料填入預先設計的試算表範本,產生發票、工時表或庫存報告,並保持一致的格式。
試試這些提示
在 /reports/monthly-data.ods 建立新的 Calc 試算表,工作表命名為 'Data'。在第 0 列新增標題 'Name'、'Value'、'Date',然後填入 5 列範例資料。將標題列套用粗體格式,並將 Value 欄套用貨幣格式。
開啟 /reports/monthly-data.ods 並匯出為三種格式:PDF 至 /exports/monthly-data.pdf、Excel 至 /exports/monthly-data.xlsx,以及 CSV 至 /exports/monthly-data.csv。驗證所有匯出成功完成。
在 /reports/sales.ods 中,使用 Sheet1 中 A0:B12 範圍的資料建立標題為 'Monthly Sales' 的折線圖。將圖表錨定在第 15 列、第 0 欄,寬度 8000,高度 6000。隨後在 B 欄新增資料驗證,要求值介於 0 和 10000 之間,錯誤訊息為 'Enter sales between 0 and 10000'。
以原子模式將此修補程式套用至 /reports/quarterly.ods:使用新的季度資料更新 A0:D4 範圍內的儲存格,使用粗體和背景顏色格式化標題列,建立顯示類別分布的圓餅圖,並重新計算所有公式。如果任何操作失敗,則復原所有變更。
最佳實務
- 使用 Calc API 時一律使用絕對檔案路徑,以避免解析錯誤
- 正確關閉工作階段,使用上下文管理程式或明確的 close() 呼叫以釋放 LibreOffice 資源
- 對應該一起成功或失敗的相關操作使用原子修補模式
- 寫入儲存格前先驗證資料類型,以防止類型轉換問題
避免
- 使用 Calc UI 中的一為基礎座標 - API 使用零為基礎索引
- 混用儲存格和範圍目標 - 即使對單一儲存格,它們也是不同的類型
- 在 close() 之後呼叫工作階段方法 - 執行操作前務必檢查工作階段狀態
- 假設圖表名稱是自動產生的 - 一律指定明確的標題以確保可靠的定位