libreoffice-calc
使用 UNO 自动化 LibreOffice Calc 电子表格
手动编辑电子表格既繁琐又容易出错。本技能通过 UNO API 以编程方式自动化 Calc 操作,实现可靠的批处理。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“libreoffice-calc”。 创建电子表格,向范围 A0:B2 添加数据,导出为 PDF
预期结果:
- 电子表格已创建在 /reports/output.ods
- 数据已写入范围 Sheet1.A0:B2(3 个单元格)
- 已导出为 PDF:/reports/output.pdf (127 KB)
正在使用“libreoffice-calc”。 从 /data/sales.ods 读取单元格 B5
预期结果:
- 单元格 Sheet1.B5:
- 值:4250.00
- 类型:数字
- 公式:无
正在使用“libreoffice-calc”。 从 A0:C10 创建柱状图,锚定在第 12 行
预期结果:
- 图表 'Sales Overview' 已在 Sheet1 上创建
- 数据范围:A0:C10(11 行,3 列)
- 位置:第 12 行,第 0 列
- 尺寸:8000 x 6000 单位
安全审计
低风险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 提取数据到结构化电子表格中,应用验证规则,并导出为多种格式以供分发。
基于模板的文档生成
使用动态数据填充预设计的电子表格模板,用于发票、时间表或库存报告,保持一致的格式。
试试这些提示
Create a new Calc spreadsheet at /reports/monthly-data.ods with a sheet named 'Data'. Add headers 'Name', 'Value', 'Date' in row 0, then populate with 5 sample rows. Apply bold formatting to the header row and currency format to the Value column.
Open /reports/monthly-data.ods and export it to three formats: PDF at /exports/monthly-data.pdf, Excel at /exports/monthly-data.xlsx, and CSV at /exports/monthly-data.csv. Verify all exports complete successfully.
In /reports/sales.ods, create a line chart titled 'Monthly Sales' using data from Sheet1 range A0:B12. Anchor the chart at row 15, column 0 with width 8000 and height 6000. Then add data validation to column B requiring values between 0 and 10000 with error message 'Enter sales between 0 and 10000'.
Apply this patch to /reports/quarterly.ods in atomic mode: Update cells in range A0:D4 with new quarterly data, format the header row with bold and background color, create a pie chart showing category distribution, and recalculate all formulas. If any operation fails, roll back all changes.
最佳实践
- 使用 Calc API 时始终使用绝对文件路径以避免解析错误
- 使用上下文管理器或显式 close() 调用来正确关闭会话以释放 LibreOffice 资源
- 对应该一起成功或失败的相关操作使用原子补丁模式
- 在写入单元格之前验证数据类型以防止类型转换问题
避免
- 使用像 Calc UI 中那样从 1 开始的坐标 - API 使用从 0 开始的索引
- 混用单元格和区域目标 - 即使是单个单元格,它们也是不同的类型
- 在 close() 之后调用会话方法 - 操作前始终检查会话状态
- 假设图表名称是自动生成的 - 始终指定明确的标题以确保可靠定位