spreadjs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

hsx CLI

hsx CLI

All operations are bash calls. Formulas recalculate instantly (no sync step needed).
所有操作均通过bash调用执行。公式会即时重新计算(无需同步步骤)。

Commands

命令

bash
hsx create file.xlsx                              # new workbook
hsx info file.xlsx                                # sheets, used ranges
hsx get file.xlsx "Sheet1!A1:C10"                 # read cells → JSON
hsx csv file.xlsx "Sheet1!A1:C10"                 # read cells → CSV
hsx set file.xlsx "Sheet1!A1:C3" '<json>'         # write cells
hsx clear file.xlsx "A1:C10"                      # clear values
hsx search file.xlsx "term" [--regex] [--sheet S] # find values
hsx copy file.xlsx "A1:C1" "A10:C10"              # copy range
hsx sheet file.xlsx list|create|delete|rename      # manage sheets
hsx rc file.xlsx insert|delete|hide|freeze rows|columns  # row/col ops
hsx resize file.xlsx --columns A:D --width 120    # column/row sizing
hsx objects file.xlsx                             # list charts, tables
hsx eval file.xlsx "code"                         # arbitrary JS
References use A1 notation:
Sheet1!A1:C10
,
A1:C10
(active sheet), or
A1
(single cell).
bash
hsx create file.xlsx                              # 新建工作簿
hsx info file.xlsx                                # 查看工作表、已使用区域
hsx get file.xlsx "Sheet1!A1:C10"                 # 读取单元格 → JSON格式
hsx csv file.xlsx "Sheet1!A1:C10"                 # 读取单元格 → CSV格式
hsx set file.xlsx "Sheet1!A1:C3" '<json>'         # 写入单元格
hsx clear file.xlsx "A1:C10"                      # 清除单元格值
hsx search file.xlsx "term" [--regex] [--sheet S] # 查找值
hsx copy file.xlsx "A1:C1" "A1:C10"              # 复制单元格区域
hsx sheet file.xlsx list|create|delete|rename      # 管理工作表
hsx rc file.xlsx insert|delete|hide|freeze rows|columns  # 行/列操作
hsx resize file.xlsx --columns A:D --width 120    # 调整列/行尺寸
hsx objects file.xlsx                             # 列出图表、表格
hsx eval file.xlsx "code"                         # 执行任意JS代码
引用采用A1表示法:
Sheet1!A1:C10
A1:C10
(当前活动工作表)或
A1
(单个单元格)。

Write

写入操作

bash
hsx set file.xlsx "A1:B3" '[
  [{"value":"Name","cellStyles":{"fontWeight":"bold"}}, {"value":"Qty","cellStyles":{"fontWeight":"bold"}}],
  [{"value":"Alice"}, {"value":4}],
  [{"value":"Bob"}, {"formula":"=B2+1"}]
]'
Each cell:
{"value": ...}
,
{"formula": "=..."}
, optional
"cellStyles": {...}
.
cellStyles:
fontWeight
(bold/normal),
fontStyle
(italic/normal),
fontSize
,
fontFamily
,
fontColor
,
backgroundColor
,
horizontalAlignment
(left/center/right),
numberFormat
.
bash
hsx set file.xlsx "A1:B3" '[
  [{"value":"Name","cellStyles":{"fontWeight":"bold"}}, {"value":"Qty","cellStyles":{"fontWeight":"bold"}}],
  [{"value":"Alice"}, {"value":4}],
  [{"value":"Bob"}, {"formula":"=B2+1"}]
]'
每个单元格的格式:
{"value": ...}
{"formula": "=..."}
,可选
"cellStyles": {...}
cellStyles支持的属性:
fontWeight
(bold/normal)、
fontStyle
(italic/normal)、
fontSize
fontFamily
fontColor
backgroundColor
horizontalAlignment
(left/center/right)、
numberFormat

Read

读取操作

bash
hsx get file.xlsx "A1:B3"
bash
hsx get file.xlsx "A1:B3"

→ {"cells":{"A1":{"value":"Name","styles":{"bold":true}},"B3":{"value":5,"formula":"B2+1"}}, ...}

→ {"cells":{"A1":{"value":"Name","styles":{"bold":true}},"B3":{"value":5,"formula":"B2+1"}}, ...}

hsx csv file.xlsx "A1:B3"
hsx csv file.xlsx "A1:B3"

→ Name,Qty

→ Name,Qty

Alice,4

Alice,4

Bob,5

Bob,5

undefined
undefined

Search

搜索操作

bash
hsx search file.xlsx "Alice"                    # case-insensitive across all sheets
hsx search file.xlsx "^Q[1-4]$" --regex         # regex
hsx search file.xlsx "Revenue" --sheet Summary   # single sheet
bash
hsx search file.xlsx "Alice"                    # 在所有工作表中进行不区分大小写的搜索
hsx search file.xlsx "^Q[1-4]$" --regex         # 使用正则表达式搜索
hsx search file.xlsx "Revenue" --sheet Summary   # 在指定工作表Summary中搜索

Copy

复制操作

bash
hsx copy file.xlsx "A1:C1" "A1:C10"             # repeat header pattern down
hsx copy file.xlsx "Sheet1!A1:B5" "Sheet2!A1:B5" # cross-sheet
bash
hsx copy file.xlsx "A1:C1" "A1:C10"             # 将表头样式向下重复复制
hsx copy file.xlsx "Sheet1!A1:B5" "Sheet2!A1:B5" # 跨工作表复制

Sheets

工作表管理

bash
hsx sheet file.xlsx list
hsx sheet file.xlsx create "Revenue"
hsx sheet file.xlsx rename "Sheet1" "Data"
hsx sheet file.xlsx delete "OldSheet"
bash
hsx sheet file.xlsx list
hsx sheet file.xlsx create "Revenue"
hsx sheet file.xlsx rename "Sheet1" "Data"
hsx sheet file.xlsx delete "OldSheet"

Rows & Columns

行与列操作

bash
hsx rc file.xlsx insert rows --ref 5 --count 3    # insert 3 rows at row 5
hsx rc file.xlsx delete columns --ref B --count 2  # delete columns B-C
hsx rc file.xlsx hide rows --ref 10                # hide row 10
hsx rc file.xlsx freeze rows --ref 1               # freeze top row
hsx rc file.xlsx unfreeze rows                     # unfreeze
bash
hsx rc file.xlsx insert rows --ref 5 --count 3    # 在第5行位置插入3行
hsx rc file.xlsx delete columns --ref B --count 2  # 删除B-C列
hsx rc file.xlsx hide rows --ref 10                # 隐藏第10行
hsx rc file.xlsx freeze rows --ref 1               # 冻结首行
hsx rc file.xlsx unfreeze rows                     # 取消冻结

Resize

调整尺寸

bash
hsx resize file.xlsx --columns A:D --width 120
hsx resize file.xlsx --rows 1:1 --height 30
hsx resize file.xlsx --columns A --width 200 --sheet Revenue
bash
hsx resize file.xlsx --columns A:D --width 120
hsx resize file.xlsx --rows 1:1 --height 30
hsx resize file.xlsx --columns A --width 200 --sheet Revenue

Eval (escape hatch)

Eval(扩展入口)

For charts, sparklines, pivot tables, conditional formatting — anything the structured commands don't cover.
bash
hsx eval file.xlsx "
  // Globals: workbook, sheet (active), GC, file
  sheet.charts.add('Revenue', GC.Spread.Sheets.Charts.ChartType.line,
    0, 120, 500, 300, 'A1:E6');
"
bash
hsx eval file.xlsx "
  const data = workbook.getSheetFromName('Data');
  data.tables.add('SalesTable', 0, 0, 10, 4,
    GC.Spread.Sheets.Tables.TableThemes.medium2);
"
bash
undefined
对于图表、迷你图、数据透视表、条件格式等结构化命令未覆盖的操作,可以使用此功能。
bash
hsx eval file.xlsx "
  // 全局变量:workbook, sheet(当前活动工作表), GC, file
  sheet.charts.add('Revenue', GC.Spread.Sheets.Charts.ChartType.line,
    0, 120, 500, 300, 'A1:E6');
"
bash
hsx eval file.xlsx "
  const data = workbook.getSheetFromName('Data');
  data.tables.add('SalesTable', 0, 0, 10, 4,
    GC.Spread.Sheets.Tables.TableThemes.medium2);
"
bash
undefined

Read values back

读取返回值

hsx eval file.xlsx " console.log('Sheets:', workbook.getSheetCount()); return sheet.getValue(0, 0); "

Stdin also works: `echo "return sheet.getValue(0,0)" | hsx eval file.xlsx`
hsx eval file.xlsx " console.log('Sheets:', workbook.getSheetCount()); return sheet.getValue(0, 0); "

也支持标准输入:`echo "return sheet.getValue(0,0)" | hsx eval file.xlsx`

SpreadJS API Reference

SpreadJS API 参考

When using
hsx eval
, you have access to the full SpreadJS API via the
GC
namespace. If you need to look up a specific API (enum values, method signatures, class properties), grep the type definitions:
bash
undefined
使用
hsx eval
时,你可以通过
GC
命名空间访问完整的SpreadJS API。如果需要查找特定API(枚举值、方法签名、类属性),可以在类型定义文件中进行搜索:
bash
undefined

Find an enum or class

查找枚举或类

grep -n "enum ChartType" ./spreadjs.d.ts grep -n "class Worksheet" ./spreadjs.d.ts
grep -n "enum ChartType" ./spreadjs.d.ts grep -n "class Worksheet" ./spreadjs.d.ts

Find methods on a class (read nearby lines for signatures)

查找类的方法(查看附近行获取签名)

grep -n "addRows|deleteRows|addColumns" ./spreadjs.d.ts
grep -n "addRows|deleteRows|addColumns" ./spreadjs.d.ts

Find available style properties

查找可用的样式属性

grep -n "fontWeight:|foreColor:|backColor:|formatter:" ./spreadjs.d.ts
grep -n "fontWeight:|foreColor:|backColor:|formatter:" ./spreadjs.d.ts

Find conditional formatting APIs

查找条件格式API

grep -n "conditionalFormats|ConditionalFormatting" ./spreadjs.d.ts

The file is at `./spreadjs.d.ts`. Use `grep -n` to find what you need, then `read` with offset to see full signatures and JSDoc examples.
grep -n "conditionalFormats|ConditionalFormatting" ./spreadjs.d.ts

该文件路径为`./spreadjs.d.ts`。使用`grep -n`查找所需内容,然后通过偏移量查看完整签名和JSDoc示例。

Best Practices

最佳实践

  • Use formulas, not hardcoded computed values:
    {"formula":"=SUM(A1:A9)"}
    not
    {"value":45}
  • Keep each
    set
    call focused; build incrementally across multiple calls
  • Use
    hsx get
    or
    hsx csv
    to verify after writes
  • Prefer uniform column widths; use empty columns for indentation
  • Always specify units in headers:
    Revenue ($mm)
    ,
    Growth (%)
  • 使用公式而非硬编码计算值:使用
    {"formula":"=SUM(A1:A9)"}
    而非
    {"value":45}
  • 每个
    set
    调用应聚焦单一任务;通过多次调用逐步构建内容
  • 写入后使用
    hsx get
    hsx csv
    验证结果
  • 优先使用统一的列宽;使用空列进行缩进
  • 始终在表头中指定单位:
    Revenue ($mm)
    Growth (%)