番外篇 —— Windows 原生部署 OpenClaw 与 Office 技能

上一篇在 macOS 上搭了 Claude Code,这篇是 Windows 侧的同类折腾:在本机(非 WSL)原生部署 OpenClaw,手动配置自定义模型与 API Key,并装上 Office(Word/PPT)处理技能。全程在 PowerShell 里完成,本机和新机都能照搬。

适用场景:在 Windows 本机(非 WSL)部署 OpenClaw,手动配置自定义模型与 API Key,并安装 Office(Word/PPT)处理技能。

一、前置确认

打开 PowerShell(Win+X → Windows PowerShell),允许本地脚本执行:

1
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Node.js 不需要提前安装,安装脚本自动处理(依次尝试 winget → Chocolatey → Scoop → portable zip 兜底)。

二、一键安装 OpenClaw

1
iwr -useb https://openclaw.ai/install.ps1 | iex

脚本自动完成:检测环境 → 安装 Node.js 24 → 全局 npm 安装 openclaw → 添加 PATH。

安装完成后重新开一个 PowerShell 窗口,验证:

1
2
openclaw --version
openclaw doctor

PATH 问题排查:如果提示 openclaw is not recognized,运行 npm config get prefix,把输出路径加入用户环境变量 PATH,重开终端即可。

三、初始化 Gateway

跳过交互式 onboard,直接初始化:

1
openclaw onboard --non-interactive --skip-health

安装 Gateway 服务(随 Windows 登录自启):

1
2
openclaw gateway install
openclaw gateway status --json

如果 Scheduled Task 因权限被拒,脚本自动 fallback 到用户 Startup 文件夹,功能相同。

当前会话手动启动 Gateway:

1
openclaw gateway run

四、配置自定义模型与 API Key

配置文件路径:%USERPROFILE%\.openclaw\openclaw.json

用记事本 / VS Code 打开,填入 provider 信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// ~/.openclaw/openclaw.json
{
// API Key 存入环境变量(不要明文写死)
env: {
CUSTOM_API_KEY: "sk-your-key-here"
},

// OpenAI 兼容接口(适用于 Azure、阿里云百炼、火山方舟等)
providers: {
"my-provider": {
kind: "openai-compatible",
baseUrl: "https://your-api-endpoint/v1",
apiKey: { env: "CUSTOM_API_KEY" }
}
},

agents: {
defaults: {
workspace: "~/.openclaw/workspace",
model: {
// 格式:provider-id/model-name
primary: "my-provider/your-model-name"
}
}
}
}

如果使用 Anthropic 原生 API Key,更简单:

1
2
3
4
5
6
7
8
{
env: { ANTHROPIC_API_KEY: "sk-ant-your-key" },
agents: {
defaults: {
model: { primary: "anthropic/claude-sonnet-4-6" }
}
}
}

保存后 Gateway 自动热重载,无需重启。

连通性验证:

1
openclaw agent --local --agent main -m "Reply with: CONFIG-OK"

五、安装 Office 技能(Word / PPT)

根据使用场景选择对应技能,搜索命令:

1
2
openclaw skills search "office"
openclaw skills search "word"

方案 A:纯文件操作(跨平台,推荐)

1
2
3
4
5
# Word / DOCX
openclaw skills install word-docx

# DOCX + PPTX 同时支持
openclaw skills install office-document-editor

能力:创建、读取、编辑 .docx / .pptx 文件,支持样式、表格、段落、修订追踪、格式保留、Git 版本集成。

方案 B:COM 自动化(需本机安装 Office/WPS)

1
openclaw skills install tiangong-wps-word-automation

能力:通过 Windows COM 接口控制 Word/WPS 程序——读取内容、替换文本、插入标题/页眉页脚、分页、合并文档、导出 PDF/TXT、替换图片。

⚠️ 仅适用于已安装 Microsoft Office 或 WPS 的 Windows 机器。

验证技能安装:

1
openclaw skills list

六、全流程验证

1
2
3
4
5
6
7
8
9
10
11
# Gateway 状态
openclaw gateway status

# 打开 Web 控制台(浏览器)
# http://127.0.0.1:18789

# 快速对话测试
openclaw agent --local --agent main -m "你好"

# 综合诊断
openclaw doctor

七、常见问题速查

现象 解决方法
openclaw is not recognized npm config get prefix 输出路径加入用户 PATH,重开终端
spawn git ENOENT 重跑安装脚本自动 bootstrap MinGit,或手动安装 Git for Windows
Gateway 启动失败 openclaw gateway run 看报错;或 openclaw doctor --fix
模型调用 401 检查 openclaw.json 中 env key 名称与 apiKey.env 字段是否一致
COM 技能找不到 Word 确认本机已安装 Microsoft Office 或 WPS,版本支持 COM 接口
安装后 PATH 未生效 关闭所有 PowerShell 窗口后重开,或注销重登 Windows