officecli-office-automation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OfficeCLI Office Automation Skill

OfficeCLI 办公自动化技能

Skill by ara.so — Devtools Skills collection.
OfficeCLI is an Office suite purpose-built for AI agents to create, read, and edit Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) files. It's a single binary with no Office installation required, featuring a unified CLI interface and built-in rendering to HTML/PNG.
ara.so提供的技能——开发工具技能合集。
OfficeCLI是一款专为AI Agent打造的办公套件,用于创建、读取和编辑Word(.docx)、Excel(.xlsx)和PowerPoint(.pptx)文件。它是一个独立二进制文件,无需安装Office,具备统一的CLI界面和内置的HTML/PNG渲染功能。

Installation

安装

macOS / Linux:
bash
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
Windows (PowerShell):
powershell
irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1 | iex
Manual installation:
  1. Download the binary for your platform from GitHub Releases
  2. Run
    officecli install
    to add to PATH
Verify installation:
bash
officecli --version
macOS / Linux:
bash
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
Windows (PowerShell):
powershell
irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1 | iex
手动安装:
  1. GitHub Releases下载对应平台的二进制文件
  2. 运行
    officecli install
    添加到PATH
验证安装:
bash
officecli --version

Core Commands

核心命令

File Operations

文件操作

Create a new document:
bash
undefined
创建新文档:
bash
undefined

Blank files

空白文件

officecli create document.docx officecli create spreadsheet.xlsx officecli create presentation.pptx
officecli create document.docx officecli create spreadsheet.xlsx officecli create presentation.pptx

With initial content

带初始内容

officecli create report.docx --prop title="Q4 Report"

**View document content:**
```bash
officecli create report.docx --prop title="Q4 Report"

**查看文档内容:**
```bash

View as outline (tree structure)

以大纲(树形结构)查看

officecli view document.docx outline
officecli view document.docx outline

View as plain text

以纯文本查看

officecli view document.docx text
officecli view document.docx text

View as HTML (opens in browser)

以HTML查看(在浏览器中打开)

officecli view document.docx html
officecli view document.docx html

View as JSON structure

以JSON结构查看

officecli view document.docx json

**Get specific elements:**
```bash
officecli view document.docx json

**获取特定元素:**
```bash

Get element details as JSON

以JSON格式获取元素详情

officecli get document.docx '/paragraph[1]' --json officecli get spreadsheet.xlsx '$Sheet1:A1' --json officecli get presentation.pptx '/slide[1]/shape[2]' --json
undefined
officecli get document.docx '/paragraph[1]' --json officecli get spreadsheet.xlsx '$Sheet1:A1' --json officecli get presentation.pptx '/slide[1]/shape[2]' --json
undefined

Live Preview

实时预览

Watch mode (auto-refresh in browser):
bash
undefined
监听模式(浏览器自动刷新):
bash
undefined
officecli watch presentation.pptx
officecli watch presentation.pptx

Custom port

自定义端口

officecli watch presentation.pptx --port 8080
officecli watch presentation.pptx --port 8080

Every edit you make will auto-refresh the browser

你进行的每一次编辑都会自动刷新浏览器

undefined
undefined

Word Documents (.docx)

Word文档 (.docx)

Path Syntax

路径语法

  • /paragraph[N]
    - Nth paragraph (1-indexed)
  • /paragraph[N]/run[M]
    - Mth run in Nth paragraph
  • /table[N]
    - Nth table
  • /table[N]/row[R]/cell[C]
    - Cell in table
  • /paragraph[N]
    - 第N个段落(从1开始计数)
  • /paragraph[N]/run[M]
    - 第N个段落中的第M个文本段
  • /table[N]
    - 第N个表格
  • /table[N]/row[R]/cell[C]
    - 表格中的单元格

Add Content

添加内容

Add paragraphs:
bash
undefined
添加段落:
bash
undefined

Simple paragraph

简单段落

officecli add report.docx / --type paragraph --prop text="Executive Summary"
officecli add report.docx / --type paragraph --prop text="Executive Summary"

Styled paragraph

带样式的段落

officecli add report.docx / --type paragraph
--prop text="Quarterly Revenue Analysis"
--prop style=Heading1
--prop align=center
officecli add report.docx / --type paragraph
--prop text="Quarterly Revenue Analysis"
--prop style=Heading1
--prop align=center

With formatting

带格式的段落

officecli add report.docx / --type paragraph
--prop text="Important notice"
--prop bold=true
--prop color=FF0000
--prop size=14

**Add runs (inline formatting):**
```bash
officecli add report.docx '/paragraph[1]' --type run \
  --prop text="bold text" \
  --prop bold=true
Add tables:
bash
undefined
officecli add report.docx / --type paragraph
--prop text="Important notice"
--prop bold=true
--prop color=FF0000
--prop size=14

**添加文本段(内联格式):**
```bash
officecli add report.docx '/paragraph[1]' --type run \
  --prop text="bold text" \
  --prop bold=true
添加表格:
bash
undefined

3x3 table

3x3表格

officecli add report.docx / --type table
--prop rows=3
--prop cols=3
officecli add report.docx / --type table
--prop rows=3
--prop cols=3

Set cell content

设置单元格内容

officecli set report.docx '/table[1]/row[1]/cell[1]'
--prop text="Header 1"

**Add images:**
```bash
officecli add report.docx / --type picture \
  --prop src=chart.png \
  --prop width=15cm \
  --prop height=10cm
Add headers/footers:
bash
undefined
officecli set report.docx '/table[1]/row[1]/cell[1]'
--prop text="Header 1"

**添加图片:**
```bash
officecli add report.docx / --type picture \
  --prop src=chart.png \
  --prop width=15cm \
  --prop height=10cm
添加页眉/页脚:
bash
undefined

Add header to first section

为第一节添加页眉

officecli add report.docx '/section[1]' --type header
--prop type=default
officecli add report.docx '/section[1]' --type header
--prop type=default

Add content to header

为页眉添加内容

officecli add report.docx '/section[1]/header[1]' --type paragraph
--prop text="Confidential Report"
--prop align=right
undefined
officecli add report.docx '/section[1]/header[1]' --type paragraph
--prop text="Confidential Report"
--prop align=right
undefined

Modify Content

修改内容

Set paragraph properties:
bash
officecli set report.docx '/paragraph[1]' \
  --prop text="Updated title" \
  --prop style=Heading1 \
  --prop align=center \
  --prop spaceBefore=240 \
  --prop spaceAfter=120
Set run properties:
bash
officecli set report.docx '/paragraph[2]/run[1]' \
  --prop bold=true \
  --prop italic=true \
  --prop font=Arial \
  --prop size=12 \
  --prop color=0000FF
设置段落属性:
bash
officecli set report.docx '/paragraph[1]' \
  --prop text="Updated title" \
  --prop style=Heading1 \
  --prop align=center \
  --prop spaceBefore=240 \
  --prop spaceAfter=120
设置文本段属性:
bash
officecli set report.docx '/paragraph[2]/run[1]' \
  --prop bold=true \
  --prop italic=true \
  --prop font=Arial \
  --prop size=12 \
  --prop color=0000FF

Remove Content

删除内容

bash
undefined
bash
undefined

Remove paragraph

删除段落

officecli remove report.docx '/paragraph[3]'
officecli remove report.docx '/paragraph[3]'

Remove table

删除表格

officecli remove report.docx '/table[1]'
undefined
officecli remove report.docx '/table[1]'
undefined

RTL and i18n Support

RTL与国际化支持

bash
undefined
bash
undefined

RTL paragraph (Arabic, Hebrew)

RTL段落(阿拉伯语、希伯来语)

officecli add report.docx / --type paragraph
--prop text="مرحبا بك"
--prop direction=rtl
--prop lang.cs=ar-SA
officecli add report.docx / --type paragraph
--prop text="مرحبا بك"
--prop direction=rtl
--prop lang.cs=ar-SA

Per-script fonts

按脚本设置字体

officecli add report.docx / --type paragraph
--prop text="Hello 世界 مرحبا"
--prop font.latin=Arial
--prop font.ea="MS Gothic"
--prop font.cs="Arial Unicode MS"
undefined
officecli add report.docx / --type paragraph
--prop text="Hello 世界 مرحبا"
--prop font.latin=Arial
--prop font.ea="MS Gothic"
--prop font.cs="Arial Unicode MS"
undefined

Excel Spreadsheets (.xlsx)

Excel电子表格 (.xlsx)

Cell Addressing

单元格寻址

  • $SheetName:A1
    - Cell A1 in named sheet
  • $Sheet1:B2:D4
    - Range B2:D4
  • /sheet[1]/cell[A1]
    - Path-based addressing
  • $SheetName:A1
    - 指定工作表中的A1单元格
  • $Sheet1:B2:D4
    - B2到D4的单元格区域
  • /sheet[1]/cell[A1]
    - 基于路径的寻址方式

Add Content

添加内容

Add sheets:
bash
undefined
添加工作表:
bash
undefined

Add new sheet

添加新工作表

officecli add budget.xlsx / --type sheet --prop name="Q1 Budget"
officecli add budget.xlsx / --type sheet --prop name="Q1 Budget"

Add with properties

添加带属性的工作表

officecli add budget.xlsx / --type sheet
--prop name="Summary"
--prop tabColor=FF0000
--prop state=visible

**Add cells:**
```bash
officecli add budget.xlsx / --type sheet
--prop name="Summary"
--prop tabColor=FF0000
--prop state=visible

**添加单元格:**
```bash

Simple value

简单值

officecli add budget.xlsx '$Sheet1:A1' --type cell
--prop value="Revenue"
officecli add budget.xlsx '$Sheet1:A1' --type cell
--prop value="Revenue"

Number with formatting

带格式的数字

officecli add budget.xlsx '$Sheet1:B1' --type cell
--prop value=125000
--prop format='$#,##0.00'
officecli add budget.xlsx '$Sheet1:B1' --type cell
--prop value=125000
--prop format='$#,##0.00'

Formula

公式

officecli add budget.xlsx '$Sheet1:C1' --type cell
--prop formula='=SUM(B1:B10)'
officecli add budget.xlsx '$Sheet1:C1' --type cell
--prop formula='=SUM(B1:B10)'

Date

日期

officecli add budget.xlsx '$Sheet1:D1' --type cell
--prop value=2024-01-15
--prop format='yyyy-mm-dd'

**Batch add cells:**
```bash
officecli add budget.xlsx '$Sheet1:D1' --type cell
--prop value=2024-01-15
--prop format='yyyy-mm-dd'

**批量添加单元格:**
```bash

Multiple cells

多个单元格

officecli add budget.xlsx '$Sheet1:A1' --type cell --prop value="Name" officecli add budget.xlsx '$Sheet1:B1' --type cell --prop value="Amount" officecli add budget.xlsx '$Sheet1:A2' --type cell --prop value="Sales" officecli add budget.xlsx '$Sheet1:B2' --type cell --prop value=50000

**Add tables:**
```bash
officecli add budget.xlsx '$Sheet1:A1' --type cell --prop value="Name" officecli add budget.xlsx '$Sheet1:B1' --type cell --prop value="Amount" officecli add budget.xlsx '$Sheet1:A2' --type cell --prop value="Sales" officecli add budget.xlsx '$Sheet1:B2' --type cell --prop value=50000

**添加表格:**
```bash

Create table from range

从单元格区域创建表格

officecli add budget.xlsx '$Sheet1:A1:C10' --type table
--prop name="SalesData"
--prop style=TableStyleMedium2
--prop showHeader=true

**Add charts:**
```bash
officecli add budget.xlsx '$Sheet1:A1:C10' --type table
--prop name="SalesData"
--prop style=TableStyleMedium2
--prop showHeader=true

**添加图表:**
```bash

Column chart

柱状图

officecli add budget.xlsx '$Sheet1' --type chart
--prop chartType=column
--prop dataRange='$Sheet1:A1:B10'
--prop title="Sales by Region"
--prop x=5cm
--prop y=2cm
officecli add budget.xlsx '$Sheet1' --type chart
--prop chartType=column
--prop dataRange='$Sheet1:A1:B10'
--prop title="Sales by Region"
--prop x=5cm
--prop y=2cm

Pie chart

饼图

officecli add budget.xlsx '$Sheet1' --type chart
--prop chartType=pie
--prop dataRange='$Sheet1:A1:B5'
--prop title="Market Share"

**Add pivot tables:**
```bash
officecli add budget.xlsx '$Sheet2:A1' --type pivottable \
  --prop sourceRange='$Sheet1:A1:D100' \
  --prop rowFields=Region \
  --prop dataFields=Sales \
  --prop name="SalesByRegion"
officecli add budget.xlsx '$Sheet1' --type chart
--prop chartType=pie
--prop dataRange='$Sheet1:A1:B5'
--prop title="Market Share"

**添加数据透视表:**
```bash
officecli add budget.xlsx '$Sheet2:A1' --type pivottable \
  --prop sourceRange='$Sheet1:A1:D100' \
  --prop rowFields=Region \
  --prop dataFields=Sales \
  --prop name="SalesByRegion"

Modify Content

修改内容

Set cell values:
bash
officecli set budget.xlsx '$Sheet1:A1' --prop value="Updated"
设置单元格值:
bash
officecli set budget.xlsx '$Sheet1:A1' --prop value="Updated"

With formatting

带格式设置

officecli set budget.xlsx '$Sheet1:B2'
--prop value=75000
--prop format='$#,##0.00'
--prop bold=true
--prop color=FF0000

**Set sheet properties:**
```bash
officecli set budget.xlsx '/sheet[1]' \
  --prop name="Renamed Sheet" \
  --prop tabColor=00FF00 \
  --prop direction=rtl
officecli set budget.xlsx '$Sheet1:B2'
--prop value=75000
--prop format='$#,##0.00'
--prop bold=true
--prop color=FF0000

**设置工作表属性:**
```bash
officecli set budget.xlsx '/sheet[1]' \
  --prop name="Renamed Sheet" \
  --prop tabColor=00FF00 \
  --prop direction=rtl

Formulas

公式

150+ built-in functions with auto-evaluation:
bash
undefined
150+内置函数,支持自动计算:
bash
undefined

Math

数学函数

officecli add budget.xlsx '$Sheet1:C1' --type cell
--prop formula='=SUM(A1:A10)'
officecli add budget.xlsx '$Sheet1:C1' --type cell
--prop formula='=SUM(A1:A10)'

Conditional

条件函数

officecli add budget.xlsx '$Sheet1:D1' --type cell
--prop formula='=IF(B1>1000,"High","Low")'
officecli add budget.xlsx '$Sheet1:D1' --type cell
--prop formula='=IF(B1>1000,"High","Low")'

Lookup

查找函数

officecli add budget.xlsx '$Sheet1:E1' --type cell
--prop formula='=VLOOKUP(A1,$Sheet2:A:B,2,FALSE)'
officecli add budget.xlsx '$Sheet1:E1' --type cell
--prop formula='=VLOOKUP(A1,$Sheet2:A:B,2,FALSE)'

Date functions

日期函数

officecli add budget.xlsx '$Sheet1:F1' --type cell
--prop formula='=TODAY()'
undefined
officecli add budget.xlsx '$Sheet1:F1' --type cell
--prop formula='=TODAY()'
undefined

Sort Data

数据排序

bash
undefined
bash
undefined

Sort range by column

按列对区域排序

officecli add budget.xlsx '$Sheet1:A1:C10' --type sort
--prop key1=B
--prop order1=desc
officecli add budget.xlsx '$Sheet1:A1:C10' --type sort
--prop key1=B
--prop order1=desc

Multi-key sort

多关键字排序

officecli add budget.xlsx '$Sheet1:A1:D20' --type sort
--prop key1=A
--prop order1=asc
--prop key2=B
--prop order2=desc
undefined
officecli add budget.xlsx '$Sheet1:A1:D20' --type sort
--prop key1=A
--prop order1=asc
--prop key2=B
--prop order2=desc
undefined

Conditional Formatting

条件格式

bash
officecli add budget.xlsx '$Sheet1:B2:B10' --type conditionalformatting \
  --prop type=colorScale \
  --prop minColor=FF0000 \
  --prop maxColor=00FF00
bash
officecli add budget.xlsx '$Sheet1:B2:B10' --type conditionalformatting \
  --prop type=colorScale \
  --prop minColor=FF0000 \
  --prop maxColor=00FF00

PowerPoint Presentations (.pptx)

PowerPoint演示文稿 (.pptx)

Path Syntax

路径语法

  • /slide[N]
    - Nth slide
  • /slide[N]/shape[M]
    - Mth shape on slide
  • /slide[N]/table[M]
    - Mth table on slide
  • /slide[N]
    - 第N张幻灯片
  • /slide[N]/shape[M]
    - 第N张幻灯片上的第M个形状
  • /slide[N]/table[M]
    - 第N张幻灯片上的第M个表格

Add Content

添加内容

Add slides:
bash
undefined
添加幻灯片:
bash
undefined

Blank slide

空白幻灯片

officecli add deck.pptx / --type slide
officecli add deck.pptx / --type slide

With title

带标题的幻灯片

officecli add deck.pptx / --type slide
--prop title="Introduction"
officecli add deck.pptx / --type slide
--prop title="Introduction"

With background

带背景的幻灯片

officecli add deck.pptx / --type slide
--prop title="Dark Theme"
--prop background=1A1A2E

**Add shapes (text boxes):**
```bash
officecli add deck.pptx / --type slide
--prop title="Dark Theme"
--prop background=1A1A2E

**添加形状(文本框):**
```bash

Simple text box

简单文本框

officecli add deck.pptx '/slide[1]' --type shape
--prop text="Hello World"
--prop x=2cm
--prop y=3cm
--prop width=10cm
--prop height=2cm
officecli add deck.pptx '/slide[1]' --type shape
--prop text="Hello World"
--prop x=2cm
--prop y=3cm
--prop width=10cm
--prop height=2cm

Styled text box

带样式的文本框

officecli add deck.pptx '/slide[1]' --type shape
--prop text="Key Findings"
--prop x=1cm
--prop y=2cm
--prop font=Arial
--prop size=32
--prop color=FFFFFF
--prop bold=true
--prop align=center

**Add images:**
```bash
officecli add deck.pptx '/slide[1]' --type shape
--prop text="Key Findings"
--prop x=1cm
--prop y=2cm
--prop font=Arial
--prop size=32
--prop color=FFFFFF
--prop bold=true
--prop align=center

**添加图片:**
```bash

Basic image

基础图片

officecli add deck.pptx '/slide[1]' --type picture
--prop src=logo.png
--prop x=1cm
--prop y=1cm
--prop width=5cm
--prop height=3cm
officecli add deck.pptx '/slide[1]' --type picture
--prop src=logo.png
--prop x=1cm
--prop y=1cm
--prop width=5cm
--prop height=3cm

With effects

带效果的图片

officecli add deck.pptx '/slide[1]' --type picture
--prop src=photo.jpg
--prop x=5cm
--prop y=5cm
--prop brightness=20
--prop contrast=10
--prop shadow=true

**Add tables:**
```bash
officecli add deck.pptx '/slide[1]' --type picture
--prop src=photo.jpg
--prop x=5cm
--prop y=5cm
--prop brightness=20
--prop contrast=10
--prop shadow=true

**添加表格:**
```bash

Create table

创建表格

officecli add deck.pptx '/slide[1]' --type table
--prop rows=3
--prop cols=3
--prop x=2cm
--prop y=5cm
officecli add deck.pptx '/slide[1]' --type table
--prop rows=3
--prop cols=3
--prop x=2cm
--prop y=5cm

Set cell content

设置单元格内容

officecli set deck.pptx '/slide[1]/table[1]/row[1]/cell[1]'
--prop text="Header 1"
--prop bold=true

**Add charts:**
```bash
officecli add deck.pptx '/slide[1]' --type chart \
  --prop chartType=column \
  --prop title="Sales Growth" \
  --prop x=2cm \
  --prop y=5cm \
  --prop width=20cm \
  --prop height=10cm
Add 3D models:
bash
officecli add deck.pptx '/slide[1]' --type 3dmodel \
  --prop src=model.glb \
  --prop x=5cm \
  --prop y=5cm \
  --prop width=10cm \
  --prop height=10cm
officecli set deck.pptx '/slide[1]/table[1]/row[1]/cell[1]'
--prop text="Header 1"
--prop bold=true

**添加图表:**
```bash
officecli add deck.pptx '/slide[1]' --type chart \
  --prop chartType=column \
  --prop title="Sales Growth" \
  --prop x=2cm \
  --prop y=5cm \
  --prop width=20cm \
  --prop height=10cm
添加3D模型:
bash
officecli add deck.pptx '/slide[1]' --type 3dmodel \
  --prop src=model.glb \
  --prop x=5cm \
  --prop y=5cm \
  --prop width=10cm \
  --prop height=10cm

Slide Transitions and Animations

幻灯片切换与动画

Add transitions:
bash
officecli set deck.pptx '/slide[2]' \
  --prop transition=morph \
  --prop duration=1000
Add animations:
bash
officecli add deck.pptx '/slide[1]/shape[1]' --type animation \
  --prop effect=fadeIn \
  --prop duration=500
添加切换效果:
bash
officecli set deck.pptx '/slide[2]' \
  --prop transition=morph \
  --prop duration=1000
添加动画:
bash
officecli add deck.pptx '/slide[1]/shape[1]' --type animation \
  --prop effect=fadeIn \
  --prop duration=500

Modify Content

修改内容

Set shape properties:
bash
officecli set deck.pptx '/slide[1]/shape[1]' \
  --prop text="Updated text" \
  --prop font=Calibri \
  --prop size=28 \
  --prop color=333333 \
  --prop fill=F0F0F0
Set slide properties:
bash
officecli set deck.pptx '/slide[1]' \
  --prop title="New Title" \
  --prop background=FFFFFF \
  --prop hidden=false
设置形状属性:
bash
officecli set deck.pptx '/slide[1]/shape[1]' \
  --prop text="Updated text" \
  --prop font=Calibri \
  --prop size=28 \
  --prop color=333333 \
  --prop fill=F0F0F0
设置幻灯片属性:
bash
officecli set deck.pptx '/slide[1]' \
  --prop title="New Title" \
  --prop background=FFFFFF \
  --prop hidden=false

Speaker Notes

演讲者备注

bash
undefined
bash
undefined

Add notes to slide

为幻灯片添加备注

officecli add deck.pptx '/slide[1]' --type notes
--prop text="Remember to mention the Q3 results"
undefined
officecli add deck.pptx '/slide[1]' --type notes
--prop text="Remember to mention the Q3 results"
undefined

Common Patterns

常见使用模式

Batch Document Generation

批量文档生成

bash
#!/bin/bash
bash
#!/bin/bash

Generate monthly reports

生成月度报告

for month in Jan Feb Mar Apr; do officecli create "report-${month}.docx" officecli add "report-${month}.docx" / --type paragraph
--prop text="${month} Report"
--prop style=Heading1 officecli add "report-${month}.docx" / --type paragraph
--prop text="Generated on $(date)" done
undefined
for month in Jan Feb Mar Apr; do officecli create "report-${month}.docx" officecli add "report-${month}.docx" / --type paragraph
--prop text="${month} Report"
--prop style=Heading1 officecli add "report-${month}.docx" / --type paragraph
--prop text="Generated on $(date)" done
undefined

CSV to Excel

CSV转Excel

bash
undefined
bash
undefined

Import CSV data

导入CSV数据

officecli create data.xlsx officecli add data.xlsx '$Sheet1' --type import
--prop src=data.csv
--prop format=csv
undefined
officecli create data.xlsx officecli add data.xlsx '$Sheet1' --type import
--prop src=data.csv
--prop format=csv
undefined

Multi-slide Presentation from Template

基于模板的多幻灯片演示文稿

bash
#!/bin/bash
bash
#!/bin/bash

Create presentation with consistent styling

创建样式统一的演示文稿

officecli create pitch.pptx
officecli create pitch.pptx

Title slide

标题幻灯片

officecli add pitch.pptx / --type slide
--prop title="Product Launch"
--prop background=1A1A2E
officecli add pitch.pptx / --type slide
--prop title="Product Launch"
--prop background=1A1A2E

Content slides

内容幻灯片

for topic in "Problem" "Solution" "Market" "Team"; do officecli add pitch.pptx / --type slide
--prop title="$topic"
--prop background=1A1A2E
officecli add pitch.pptx '/slide[-1]' --type shape
--prop text="Content for $topic"
--prop x=2cm
--prop y=5cm
--prop color=FFFFFF done
undefined
for topic in "Problem" "Solution" "Market" "Team"; do officecli add pitch.pptx / --type slide
--prop title="$topic"
--prop background=1A1A2E
officecli add pitch.pptx '/slide[-1]' --type shape
--prop text="Content for $topic"
--prop x=2cm
--prop y=5cm
--prop color=FFFFFF done
undefined

Automated Report with Charts

带图表的自动化报告

bash
#!/bin/bash
bash
#!/bin/bash

Generate Excel report with chart

生成带图表的Excel报告

officecli create sales.xlsx
officecli create sales.xlsx

Add headers

添加表头

officecli add sales.xlsx '$Sheet1:A1' --type cell --prop value="Month" officecli add sales.xlsx '$Sheet1:B1' --type cell --prop value="Revenue"
officecli add sales.xlsx '$Sheet1:A1' --type cell --prop value="Month" officecli add sales.xlsx '$Sheet1:B1' --type cell --prop value="Revenue"

Add data

添加数据

officecli add sales.xlsx '$Sheet1:A2' --type cell --prop value="January" officecli add sales.xlsx '$Sheet1:B2' --type cell --prop value=50000 officecli add sales.xlsx '$Sheet1:A3' --type cell --prop value="February" officecli add sales.xlsx '$Sheet1:B3' --type cell --prop value=65000 officecli add sales.xlsx '$Sheet1:A4' --type cell --prop value="March" officecli add sales.xlsx '$Sheet1:B4' --type cell --prop value=72000
officecli add sales.xlsx '$Sheet1:A2' --type cell --prop value="January" officecli add sales.xlsx '$Sheet1:B2' --type cell --prop value=50000 officecli add sales.xlsx '$Sheet1:A3' --type cell --prop value="February" officecli add sales.xlsx '$Sheet1:B3' --type cell --prop value=65000 officecli add sales.xlsx '$Sheet1:A4' --type cell --prop value="March" officecli add sales.xlsx '$Sheet1:B4' --type cell --prop value=72000

Add chart

添加图表

officecli add sales.xlsx '$Sheet1' --type chart
--prop chartType=line
--prop dataRange='$Sheet1:A1:B4'
--prop title="Monthly Revenue"
--prop x=5cm
--prop y=2cm
undefined
officecli add sales.xlsx '$Sheet1' --type chart
--prop chartType=line
--prop dataRange='$Sheet1:A1:B4'
--prop title="Monthly Revenue"
--prop x=5cm
--prop y=2cm
undefined

Extract and Transform

提取与转换

bash
#!/bin/bash
bash
#!/bin/bash

Extract text from Word doc, process, create new doc

从Word文档提取文本,处理后创建新文档

Extract text

提取文本

text=$(officecli view input.docx text)
text=$(officecli view input.docx text)

Process (example: convert to uppercase)

处理(示例:转换为大写)

processed=$(echo "$text" | tr '[:lower:]' '[:upper:]')
processed=$(echo "$text" | tr '[:lower:]' '[:upper:]')

Create new document

创建新文档

officecli create output.docx officecli add output.docx / --type paragraph --prop text="$processed"
undefined
officecli create output.docx officecli add output.docx / --type paragraph --prop text="$processed"
undefined

Integration with Scripts

与脚本集成

Python Integration

Python集成

python
import subprocess
import json

def create_report(title, content):
    """Create a Word document using OfficeCLI."""
    filename = f"{title}.docx"
    
    # Create document
    subprocess.run(["officecli", "create", filename])
    
    # Add title
    subprocess.run([
        "officecli", "add", filename, "/",
        "--type", "paragraph",
        "--prop", f"text={title}",
        "--prop", "style=Heading1"
    ])
    
    # Add content
    for paragraph in content:
        subprocess.run([
            "officecli", "add", filename, "/",
            "--type", "paragraph",
            "--prop", f"text={paragraph}"
        ])
    
    return filename

def get_cell_value(filename, cell):
    """Get cell value from Excel file."""
    result = subprocess.run([
        "officecli", "get", filename, cell, "--json"
    ], capture_output=True, text=True)
    
    data = json.loads(result.stdout)
    return data.get("attributes", {}).get("value")
python
import subprocess
import json

def create_report(title, content):
    """使用OfficeCLI创建Word文档。"""
    filename = f"{title}.docx"
    
    # 创建文档
    subprocess.run(["officecli", "create", filename])
    
    # 添加标题
    subprocess.run([
        "officecli", "add", filename, "/",
        "--type", "paragraph",
        "--prop", f"text={title}",
        "--prop", "style=Heading1"
    ])
    
    # 添加内容
    for paragraph in content:
        subprocess.run([
            "officecli", "add", filename, "/",
            "--type", "paragraph",
            "--prop", f"text={paragraph}"
        ])
    
    return filename

def get_cell_value(filename, cell):
    """从Excel文件获取单元格值。"""
    result = subprocess.run([
        "officecli", "get", filename, cell, "--json"
    ], capture_output=True, text=True)
    
    data = json.loads(result.stdout)
    return data.get("attributes", {}).get("value")

Usage

使用示例

create_report("Q1 Summary", [ "Revenue increased by 25%.", "Customer satisfaction improved.", "New product launch successful." ])
value = get_cell_value("budget.xlsx", "$Sheet1:B2") print(f"Budget value: {value}")
undefined
create_report("Q1 Summary", [ "Revenue increased by 25%.", "Customer satisfaction improved.", "New product launch successful." ])
value = get_cell_value("budget.xlsx", "$Sheet1:B2") print(f"Budget value: {value}")
undefined

Node.js Integration

Node.js集成

javascript
const { execSync } = require('child_process');

function createPresentation(title, slides) {
  const filename = `${title}.pptx`;
  
  // Create presentation
  execSync(`officecli create "${filename}"`);
  
  // Add slides
  slides.forEach(slide => {
    execSync(`officecli add "${filename}" / --type slide --prop title="${slide.title}"`);
    
    if (slide.content) {
      execSync(`officecli add "${filename}" '/slide[-1]' --type shape --prop text="${slide.content}" --prop x=2cm --prop y=5cm`);
    }
  });
  
  return filename;
}

function viewAsHTML(filename) {
  execSync(`officecli view "${filename}" html`);
}

// Usage
const slides = [
  { title: "Introduction", content: "Welcome to our presentation" },
  { title: "Main Points", content: "Key findings and results" },
  { title: "Conclusion", content: "Thank you" }
];

const file = createPresentation("meeting", slides);
viewAsHTML(file);
javascript
const { execSync } = require('child_process');

function createPresentation(title, slides) {
  const filename = `${title}.pptx`;
  
  // 创建演示文稿
  execSync(`officecli create "${filename}"`);
  
  // 添加幻灯片
  slides.forEach(slide => {
    execSync(`officecli add "${filename}" / --type slide --prop title="${slide.title}"`);
    
    if (slide.content) {
      execSync(`officecli add "${filename}" '/slide[-1]' --type shape --prop text="${slide.content}" --prop x=2cm --prop y=5cm`);
    }
  });
  
  return filename;
}

function viewAsHTML(filename) {
  execSync(`officecli view "${filename}" html`);
}

// 使用示例
const slides = [
  { title: "Introduction", content: "Welcome to our presentation" },
  { title: "Main Points", content: "Key findings and results" },
  { title: "Conclusion", content: "Thank you" }
];

const file = createPresentation("meeting", slides);
viewAsHTML(file);

Troubleshooting

故障排除

Binary not found after installation

安装后找不到二进制文件

bash
undefined
bash
undefined

Check if binary is in PATH

检查二进制文件是否在PATH中

which officecli
which officecli

If not, run install again

如果不在,重新运行安装命令

officecli install
officecli install

Or manually add to PATH

或者手动添加到PATH

export PATH="$PATH:$HOME/.officecli/bin"
undefined
export PATH="$PATH:$HOME/.officecli/bin"
undefined

File not opening in Office

文件无法在Office中打开

bash
undefined
bash
undefined

Verify file is valid

验证文件是否有效

officecli view document.docx outline
officecli view document.docx outline

Check file wasn't corrupted

检查文件是否损坏

file document.docx
file document.docx

Should show: "Microsoft Word 2007+"

应显示:"Microsoft Word 2007+"

undefined
undefined

Preview not refreshing in watch mode

监听模式下预览不刷新

bash
undefined
bash
undefined

Ensure watch server is running

确保监听服务器正在运行

officecli watch document.docx
officecli watch document.docx

Check if port is blocked

检查端口是否被占用

officecli watch document.docx --port 8081
officecli watch document.docx --port 8081

Clear browser cache or hard refresh (Ctrl+Shift+R / Cmd+Shift+R)

清除浏览器缓存或强制刷新(Ctrl+Shift+R / Cmd+Shift+R)

undefined
undefined

Permission denied errors

权限拒绝错误

bash
undefined
bash
undefined

Ensure file isn't open in another program

确保文件未在其他程序中打开

Close Office/LibreOffice/other editors

关闭Office/LibreOffice或其他编辑器

Check file permissions

检查文件权限

ls -l document.docx chmod 644 document.docx
undefined
ls -l document.docx chmod 644 document.docx
undefined

Invalid path errors

无效路径错误

bash
undefined
bash
undefined

Verify document structure first

先验证文档结构

officecli view document.docx outline
officecli view document.docx outline

Paths are 1-indexed: /paragraph[1], /slide[1]

路径从1开始计数:/paragraph[1], /slide[1]

Use --json to see exact paths

使用--json查看确切路径

officecli get document.docx / --json
undefined
officecli get document.docx / --json
undefined

Formula not calculating in Excel

Excel公式未计算

bash
undefined
bash
undefined

OfficeCLI auto-evaluates 150+ functions

OfficeCLI自动计算150+种函数

Unsupported functions show #NAME? error

不支持的函数会显示#NAME?错误

Check formula syntax:

检查公式语法:

officecli get spreadsheet.xlsx '$Sheet1:A1' --json
undefined
officecli get spreadsheet.xlsx '$Sheet1:A1' --json
undefined

RTL text not rendering correctly

RTL文本渲染不正确

bash
undefined
bash
undefined

Set direction property

设置方向属性

officecli set document.docx '/paragraph[1]'
--prop direction=rtl
--prop lang.cs=ar-SA
officecli set document.docx '/paragraph[1]'
--prop direction=rtl
--prop lang.cs=ar-SA

For complex scripts, set appropriate font

对于复杂脚本,设置合适的字体

officecli set document.docx '/paragraph[1]'
--prop font.cs="Arial Unicode MS"
undefined
officecli set document.docx '/paragraph[1]'
--prop font.cs="Arial Unicode MS"
undefined

Image not appearing

图片不显示

bash
undefined
bash
undefined

Check image path is correct and file exists

检查图片路径是否正确且文件存在

ls -l image.png
ls -l image.png

Ensure image format is supported (PNG/JPG/GIF/SVG)

确保图片格式受支持(PNG/JPG/GIF/SVG)

file image.png
file image.png

Use absolute path if relative path fails

如果相对路径失败,使用绝对路径

officecli add doc.docx / --type picture --prop src=/full/path/to/image.png
undefined
officecli add doc.docx / --type picture --prop src=/full/path/to/image.png
undefined

Configuration

配置

OfficeCLI is designed to work out-of-the-box with no configuration needed. All settings are passed as command-line flags.
Common flags:
  • --json
    - Output as JSON
  • --port PORT
    - Custom port for watch server (default: 26315)
  • --prop key=value
    - Set element properties
OfficeCLI开箱即用,无需额外配置。所有设置都通过命令行标志传递。
常见标志:
  • --json
    - 以JSON格式输出
  • --port PORT
    - 自定义监听服务器端口(默认:26315)
  • --prop key=value
    - 设置元素属性

Documentation

文档

Key Concepts

核心概念

  1. XPath-like addressing: All elements use path notation (
    /paragraph[1]
    ,
    $Sheet1:A1
    ,
    /slide[1]/shape[2]
    )
  2. Unified interface: Same
    add
    ,
    set
    ,
    get
    ,
    remove
    ,
    view
    verbs across all formats
  3. Live preview:
    watch
    command provides real-time browser preview with auto-refresh
  4. No dependencies: Single binary, no Office installation needed
  5. AI-first design: Commands optimized for LLM generation and automation
  6. Format preservation: Edit documents without breaking complex formatting
  7. Rich i18n: Full RTL support, per-script fonts, locale-aware rendering
When helping users with OfficeCLI, focus on the unified command structure and path-based addressing. The same patterns work across Word, Excel, and PowerPoint with format-specific properties.
  1. 类XPath寻址: 所有元素使用路径表示法(
    /paragraph[1]
    ,
    $Sheet1:A1
    ,
    /slide[1]/shape[2]
  2. 统一界面: 所有格式都使用相同的
    add
    set
    get
    remove
    view
    命令
  3. 实时预览:
    watch
    命令提供浏览器实时预览并自动刷新
  4. 无依赖: 独立二进制文件,无需安装Office
  5. AI优先设计: 命令针对LLM生成和自动化进行优化
  6. 格式保留: 编辑文档时不会破坏复杂格式
  7. 丰富的国际化: 完整的RTL支持、按脚本设置字体、区域感知渲染
在为用户提供OfficeCLI帮助时,重点关注统一的命令结构和基于路径的寻址方式。相同的模式适用于Word、Excel和PowerPoint,仅需调整格式特定的属性。