How AI Agents Can Control WPS Office From the Command Line: A Complete Guide to cli-anything-wps

Can AI Agents Directly Control Closed-Source Office Software?

Yes — as long as the software exposes a programmable interface, and cli-anything-wps proves it. It wraps WPS Office’s COM automation interface into 47 CLI commands, enabling AI agents to perform every WPS operation from the terminal just as they would with open-source tools like GIMP or Blender.

For a long time, AI agents’ ability to control desktop software has been confined to a narrow circle. CLI-Anything is an outstanding project in this space — a single command can drive GIMP for image editing, Blender for 3D modeling, or LibreOffice for document creation. But it has one hard limitation: it only supports open-source software.

That limitation matters a lot in practice. A massive share of industry-standard software is closed-source: WPS Office is the dominant office suite in China, and the Adobe ecosystem is the de facto standard in design. Their closed-source nature has kept AI agents locked out — even though these are precisely the tools people need most in their daily work.

cli-anything-wps offers a straightforward answer: if a software has a programmable interface, it can be plugged into an AI agent’s command system. WPS exposes a full COM automation interface on Windows, highly compatible with Microsoft Office VBA. Following CLI-Anything’s 7-stage Harness methodology, this project builds a WPS controller from scratch, mapping 47 CLI commands to WPS’s three core applications.

Reflection: This project reshaped my understanding of the “open-source vs. closed-source” divide in the age of AI agents. The advantage of open-source software isn’t that it’s “better” — it’s that its interfaces are visible. But as long as closed-source software is willing to expose automation interfaces, that capability gap can be completely closed.

Office automation
Image source: Unsplash


What Is cli-anything-wps: Translating COM Interfaces Into CLI Commands

Core question this section answers: What exactly does cli-anything-wps do, and what problem does it solve?

It translates WPS Office’s COM automation interface into 47 structured CLI commands, allowing AI agents to create, edit, format, and export documents without ever opening a graphical interface. This means you can manipulate WPS documents from the terminal, from scripts, or from within an AI agent’s call chain — treating them almost like text files.

The tool is built on the CLI-Anything architecture. CLI-Anything itself is a general-purpose framework for “driving desktop software from the command line,” while cli-anything-wps is its WPS-specific implementation. The relationship is simple: the framework provides the methodology and runtime; cli-anything-wps provides the WPS-specific command set and backend adapter.

Its core value can be captured in one sentence: it gives closed-source software the same level of automated programmability as open-source software.

Command line interface
Image source: Unsplash


System Requirements and Installation: Up and Running in Three Steps

Core question this section answers: What environment do I need, and how do I install it?

You need Windows 10/11, WPS Office 2019 or later, Python 3.10+, and pywin32 — two commands to install. The process involves no compilation and no complex environment variable configuration.

Environment Requirements

Component Requirement Notes
Operating System Windows 10 / 11 COM is a Windows-specific technology; macOS and Linux are not supported
WPS Office 2019 or later Both Home & Student and Professional editions work
Python 3.10 or later Required for type annotation syntax features
pywin32 pip install pywin32 Bridge for Python to call COM interfaces

A critical point to understand: this tool does not simulate file formats — it controls the real WPS program. Its rendering output is identical to manual operation because WPS itself is doing the work. This also explains why WPS must be installed — without a WPS process, the COM interface has no target to call.

Installation Methods

Method 1: Direct pip install (recommended)

pip install git+https://github.com/yb2460/cli-anything-wps.git

This is the simplest approach — one command pulls the repository and installs it into the current Python environment.

Method 2: Clone and install locally

git clone https://github.com/yb2460/cli-anything-wps.git
cd cli-anything-wps
pip install -e .

The -e flag installs in development mode, so source code changes take effect without reinstallation. This is ideal for anyone who needs to customize or debug the tool.

Verify Installation

cli-anything-wps --help

If you see the command help output, the installation succeeded. The tool is now ready to communicate with WPS.

Scenario: Imagine you’re a tech lead who needs to auto-generate weekly report documents in a CI/CD pipeline. Just run the installation steps above on your Windows build machine, and your pipeline scripts can call cli-anything-wps commands directly — no manual intervention required.


Controlling WPS Writer: From Document Creation to PDF Export

Core question this section answers: How do I perform all WPS Writer editing operations from the command line?

Through the writer subcommand group, you can create documents, add paragraphs and headings, insert tables, set font formatting, perform find-and-replace, and export to six formats: DOCX, PDF, TXT, HTML, RTF, and ODT. The entire process happens without opening a WPS window.

Creating and Editing Content

# Create a new WPS Writer document, saving the project file as report.json
cli-anything-wps document new --type writer --name "Annual Report" -o report.json

# Add a level-1 heading
cli-anything-wps --project report.json writer add-heading -t "Introduction" -l 1

# Add a body paragraph
cli-anything-wps --project report.json writer add-paragraph -t "This report was auto-generated by AI."

# Insert a 3-row, 3-column table
cli-anything-wps --project report.json writer add-table -r 3 -c 3

Several design details are worth noting:

  • The --project parameter: Every document operation is chained through a project file. report.json records the document’s state, session history, and other metadata. All subsequent operations reference this file. This is a core design pattern of the CLI-Anything architecture — using a JSON file as a “document handle.”
  • -l 1 for heading level: Supports multiple heading levels for building document structure.
  • add-table with -r and -c: Directly specifies row and column counts. The table is inserted at the current cursor position.

Formatting and Find-and-Replace

The writer module also supports setting font, font size, color, bold, italic, and alignment, along with find-and-replace and page setup (headers, footers, margins). These operations are performed through a combination of the style command group and writer subcommands.

Multi-Format Export

# Export as Word format
cli-anything-wps --project report.json export render report.docx -p docx

# Export as PDF
cli-anything-wps --project report.json export render report.pdf -p pdf

Export is handled by the export render command, with the -p parameter specifying the target format. Six formats are supported: DOCX, PDF, TXT, HTML, RTF, and ODT.

Scenario: A company needs to convert dozens of department reports to PDF for archiving every month. Previously, someone had to open each file manually and use “Save As.” Now a simple script can iterate through a directory of project files, calling export render -p pdf for each one, and complete the entire batch in seconds.


Controlling WPS Spreadsheet: Batch Data Writing and Formula Calculation

Core question this section answers: How do I control WPS Spreadsheet for data operations from the command line?

Through the calc subcommand group, you can manage worksheets (add/delete/rename), read and write cells (single and batch ranges), set formulas, merge cells, and perform sorting, filtering, and conditional formatting — then export to XLSX, PDF, CSV, or HTML.

Cell Read and Write

# Create a new spreadsheet document
cli-anything-wps document new --type calc --name "Data" -o data.json

# Write to a single cell
cli-anything-wps --project data.json calc set-cell A1 "Product Name"
cli-anything-wps --project data.json calc set-cell A2 "WPS CLI"

# Batch write to a range
cli-anything-wps --project data.json calc set-range A3 -d '[["Zhang San",28],["Li Si",35]]'

The difference between set-cell and set-range is straightforward: the former operates on one cell, the latter on a rectangular region. The -d parameter of set-range accepts a JSON-formatted two-dimensional array — particularly important in AI agent scenarios, where structured data generated by an agent can be poured directly into a spreadsheet without format conversion.

Worksheet Management

# Add a new worksheet
cli-anything-wps --project data.json calc add-sheet

# Rename a worksheet
cli-anything-wps --project data.json calc rename-sheet --index 1 --name "Summary"

# List all worksheets
cli-anything-wps --project data.json calc list-sheets

# Delete a worksheet
cli-anything-wps --project data.json calc remove-sheet --index 2

Export

cli-anything-wps --project data.json export render data.xlsx -p xlsx

Scenario: A data analyst needs to export CSV data from a system daily, fill it into a WPS spreadsheet template with headers, formulas, and conditional formatting, then send the result to management. With cli-anything-wps, this entire workflow can be fully automated: the script reads the CSV → set-range batch writes the data → sets formulas → export render -p pdf outputs the final file.

Data processing
Image source: Unsplash


Controlling WPS Presentation: Auto-Generating Slides

Core question this section answers: How do I create and edit WPS presentations from the command line?

Through the impress subcommand group, you can manage slides (add/delete/sort/copy), edit titles and body content, draw shapes (rectangle, rounded rectangle, ellipse, arrow), place text boxes at any position with custom font, color, and size — then export to PPTX or PDF.

Creating a Presentation

# Create a new presentation document
cli-anything-wps document new --type impress --name "Presentation" -o slides.json

# Add a slide with a title and body
cli-anything-wps --project slides.json impress add-slide -t "Title Slide" -c "Body content here"

# Add a text box element on slide 0
cli-anything-wps --project slides.json impress add-element 0 --type text_box --text "Hello!"

# Export
cli-anything-wps --project slides.json export render slides.pptx -p pptx

The add-element command supports multiple shape types: text_box, rectangle, round_rectangle, ellipse, and arrow. Each shape can be configured with position, dimensions, color, and font properties.

Scenario: A consulting firm generates client presentation decks every week based on the same data template. The number of slides, layout, and chart positions are fixed — only the data changes. With cli-anything-wps, an AI agent can auto-fill each slide’s text boxes with the current week’s data, then export the PPTX for delivery to the client.


AI Agent Mode: Why –json Is the Key to the Entire Project

Core question this section answers: How does this tool work with AI agents?

Every command supports the --json flag, returning structured JSON data instead of human-readable text, so AI agents can directly parse execution results and decide on next actions. This is the feature that distinguishes cli-anything-wps from ordinary scripting tools.

# Create a document, returning results in JSON format
cli-anything-wps --json document new --type writer --name "test"

# Query current session status, returning structured data
cli-anything-wps --json --project test.json session status

Without --json, commands output human-friendly text descriptions. With --json, the output becomes a machine-parseable JSON object. This design makes the AI agent’s call chain extremely clean:

  1. The agent sends a CLI command (with --json)
  2. The tool executes the operation and returns a JSON result
  3. The agent parses the JSON, determines success/failure, and retrieves document state
  4. The agent decides the next command based on the result

This “command as function call” pattern is essentially CLI-based Function Calling. It doesn’t depend on any specific AI framework or protocol — any agent capable of executing system commands can integrate with it.

Reflection: When people discuss AI agents controlling software, the first instinct is often the “screenshot + mouse click” visual approach. But cli-anything-wps takes a different path — calling the software’s programming interface directly. These two paths aren’t alternatives; they’re complementary. Software with interfaces gets direct CLI connections; software without interfaces falls back to visual approaches. The latter is slow, expensive, and unreliable; the former is fast, cheap, and robust.


Interactive REPL and Session Management: The Middle Ground Between Humans and Agents

Core question this section answers: Can a person use this directly, not just scripts and agents?

Yes. Running cli-anything-wps without any arguments enters an interactive REPL mode where you can type commands one at a time, see results immediately, and still benefit from undo/redo and session persistence.

REPL Mode

cli-anything-wps

Once inside, you can enter commands line by line, much like a Python interpreter. This is ideal for exploratory work — when you’re unsure about a command’s effect, test it in the REPL first, then write it into a script once confirmed.

Session Management

Three core session capabilities:

Command Function
session status View current session state
session undo Undo the last operation
session redo Redo a previously undone operation
session history View operation history

Up to 50 steps of undo/redo history are supported. This is sufficient for most document editing scenarios. Session state is persisted in the project JSON file — even if you close the terminal and reopen it later, specifying the same --project file lets you pick up exactly where you left off.

Scenario: You’re editing a document in the REPL and have added 20 paragraphs in a row, then realize the 8th paragraph was wrong. No need to start over — just session undo back to the state after step 7, make your correction, and continue. The experience is almost identical to pressing Ctrl+Z in the WPS GUI, except you never opened WPS.


Silent Background Mode: The Right Way to Do Batch Automation

Core question this section answers: How do I make WPS execute operations without popping up a window?

By setting app.Visible = False, WPS runs silently in the background with no visible windows — ideal for batch report generation, format conversion, and other scenarios that don’t require human interaction. This means you can run the tool on servers, in CI/CD pipelines, and in unattended environments.

Background mode isn’t enabled through a separate CLI flag. Instead, it’s controlled at the WPS backend layer (wps_backend.py) by setting the COM object’s Visible property. When Visible is set to False, the WPS process still exists (visible in Task Manager) but displays no windows.

Scenario: A finance department needs to convert 200 Excel reports to PDF every month. If each conversion popped up a WPS window, it would be slow and could interfere with other work due to window focus switching. In background mode, all 200 reports are silently converted in minutes, and the user barely notices WPS is running.

Background automation
Image source: Unsplash


How It Works Under the Hood: From CLI Command to COM Call

Core question this section answers: How does a CLI command become an actual operation inside WPS?

A command passes through six layers: CLI layer (Click framework) → Session layer (undo/redo/persistence) → Core module (business logic) → WPS Backend (COM wrapper) → COM interface → WPS Office. Each layer has a clear, decoupled responsibility.

CLI Command (Click)
    │
    ▼
Session Layer — Undo/Redo/Persistence
    │
    ▼
Core Module — writer.py / calc.py / impress.py / export.py
    │
    ▼
WPS Backend (wps_backend.py) — COM Interface Wrapper
    │
    ▼
COM Interface — KWPS / KET / KWPP.Application
    │
    ▼
WPS Office — Executes the Actual Operation

Layer Responsibilities

  • CLI Layer: Built on Python’s Click framework, responsible for parsing command-line arguments and routing to the appropriate handler function. All 47 commands are defined here.
  • Session Layer: Maintains an operation history stack, supporting undo/redo. It captures state before each operation and restores to the previous snapshot when undoing.
  • Core Module: Organized by application — writer.py handles word processing, calc.py handles spreadsheets, impress.py handles presentations, and export.py handles exporting. Each file translates CLI parameters into backend calls.
  • WPS Backend: wps_backend.py is the project’s “translator,” converting the Core module’s generic calls into WPS-specific COM calls.
  • COM Interface: Windows COM (Component Object Model) is Microsoft’s cross-process communication technology. WPS exposes its automation interface by registering ProgIDs.

Three COM Entry Points

ProgID Corresponding Application Analog
KWPS.Application WPS Writer Similar to Microsoft Word
KET.Application WPS Spreadsheet Similar to Microsoft Excel
KWPP.Application WPS Presentation Similar to Microsoft PowerPoint

These three ProgIDs are COM component identifiers that WPS registers in the Windows system. When wps_backend.py calls win32com.client.Dispatch("KWPS.Application"), Windows launches (or connects to an already running) WPS Writer process and returns a programmable object.

Reflection: This six-layer architecture may seem “heavy,” but every layer has a clear reason to exist for a tool that needs to support long-running AI agent interactions. The Session layer lets agents try things and roll back. The Core layer keeps different application logic isolated. The Backend layer means switching the underlying application (WPS vs. Office) requires changing only one file. This layering isn’t over-engineering — it’s a necessary response to complexity.


Style Management: Controlling Document Appearance at Scale

Core question this section answers: How do I batch-set and manage document formatting styles?

Through the style subcommand group, you can create, modify, list, apply, and remove styles — avoiding the tedious process of setting formatting on each paragraph individually. Style management is the “leverage point” of document automation: define a style once, apply it across the entire document, and future changes only require modifying the style definition.

style create|modify|list|apply|remove

This command group sits at the same level as writer/calc/impress, indicating that styles are treated as a cross-application capability. In practice, you’d typically define a set of styles first (e.g., “Body Text,” “Heading 1,” “Heading 2,” “Code Block”), then apply them uniformly when adding content via style apply.

Scenario: A law firm requires all legal documents to use a unified font (SimSun, size 12), line spacing (1.5x), and heading format. By pre-defining these styles with the style commands, AI agent-generated documents automatically adopt the correct formatting — no need to repeat format parameters every time a document is generated.


Microsoft Office Compatibility: A One-Line Change

Core question this section answers: Can I use this tool with Microsoft Office instead of WPS?

Yes. WPS’s COM interface is highly compatible with MS Office VBA — simply replace the three ProgIDs in wps_backend.py with their Office counterparts. This isn’t a coincidence; it’s the result of WPS deliberately maintaining compatibility with Office’s automation ecosystem.

Specifically:

Original ProgID (WPS) Replace With
KWPS.Application Word.Application
KET.Application Excel.Application
KWPP.Application PowerPoint.Application

After replacement, the tool drives Microsoft Office via COM instead of WPS. Because of the high consistency between the two in their document object models (DOM), most commands work without any modification.

Reflection: This “one-line code change to switch backends” capability perfectly demonstrates the value of layered architecture. If COM calls were scattered across all 47 command handlers, switching backends would be a nightmare. But because all COM calls are centralized in a single file — wps_backend.py — the switch requires changing only that file. This is the Dependency Inversion Principle in action within a CLI tool.


Complete Command Reference

Core question this section answers: How many commands does this tool provide, and what does each one do?

A total of 47 commands, organized into eight categories: document management, word processing, spreadsheet, presentation, style management, export/rendering, session management, and interactive mode. Here is the full command tree:

cli-anything-wps
├── document new|open|save|info|profiles|json    Document Management
├── writer                                         Word Processing
│   ├── add-paragraph|add-heading|add-list
│   ├── add-table|add-image|add-page-break
│   ├── remove|list|set-text|find-replace
├── calc                                           Spreadsheet
│   ├── add-sheet|remove-sheet|rename-sheet
│   ├── set-cell|get-cell|set-range|merge-cells
│   └── list-sheets
├── impress                                        Presentation
│   ├── add-slide|remove-slide|set-content
│   └── list-slides|add-element
├── style create|modify|list|apply|remove          Style Management
├── export presets|preset-info|render              Export & Rendering
├── session status|undo|redo|history               Session Management
└── repl                                           Interactive Mode

A few commands worth highlighting:

  • document profiles: Lists supported document type configurations, helping you understand the capabilities available in your current environment.
  • document json: Outputs the complete document structure in JSON format — highly useful for agents that need to understand document content.
  • export presets and export preset-info: List and inspect available export format presets. You can verify supported formats and parameters before running export render.

Practical Summary / Action Checklist

Here is the complete step-by-step checklist for going from zero to productive with cli-anything-wps:

  • [ ] Confirm your runtime environment is Windows 10 or Windows 11
  • [ ] Install WPS Office 2019 or later (Home & Student or Professional edition)
  • [ ] Install Python 3.10 or later
  • [ ] Run pip install pywin32 to install the COM communication dependency
  • [ ] Run pip install git+https://github.com/yb2460/cli-anything-wps.git to install the tool
  • [ ] Run cli-anything-wps --help to verify successful installation
  • [ ] Use document new --type writer/calc/impress to create a document
  • [ ] Use the corresponding subcommand groups to edit content
  • [ ] Use export render to export to your target format
  • [ ] For AI agent integration, add the --json flag to all commands
  • [ ] For interactive use, run cli-anything-wps with no arguments to enter REPL
  • [ ] For background execution, modify the Visible property to False in wps_backend.py
  • [ ] To switch to Microsoft Office, replace the three ProgIDs in wps_backend.py

One-Page Summary

Dimension Details
Project Name cli-anything-wps
Core Function Wraps WPS Office COM interface into 47 CLI commands
Based On CLI-Anything 7-stage Harness methodology
Supported Apps WPS Writer, WPS Spreadsheet, WPS Presentation
Total Commands 47, across 8 categories
Export Formats DOCX / PDF / TXT / HTML / RTF / ODT / XLSX / CSV / PPTX
AI Adaptation All commands support --json structured output
Interactive Mode Run with no arguments to enter REPL
Session Support Persistence + 50-step undo/redo
Background Mode Visible=False for silent execution
Operating System Windows only (COM technology limitation)
Python Version 3.10+
Dependencies pywin32, WPS Office 2019+
Office Compatibility Switch to Microsoft Office by replacing ProgIDs
License MIT License

Frequently Asked Questions

Q: Why must WPS be installed to use this tool?

This tool controls the real WPS program process through the COM interface — it does not parse or generate file formats on its own. This means its rendering output and layout results are identical to manual WPS operation, but it requires WPS to be present on the system as a callable process.

Q: Does it support macOS or Linux?

No. COM (Component Object Model) is a Windows-exclusive cross-process communication technology. macOS and Linux do not have this mechanism. For document operations on non-Windows environments, consider using LibreOffice, which is natively supported by CLI-Anything.

Q: Does it support Microsoft Office?

WPS’s COM interface is highly compatible with MS Office VBA. If you only have Microsoft Office and not WPS, replace KWPS.Application with Word.Application, KET.Application with Excel.Application, and KWPP.Application with PowerPoint.Application in wps_backend.py.

Q: Can it be used for batch automation tasks?

Yes. Setting app.Visible = False makes WPS run silently in the background without displaying any windows. This is ideal for unattended scenarios like batch report generation, format conversion, and data filling.

Q: How many undo/redo steps are supported?

Up to 50 steps. Operation history is persisted in the project JSON file — close the terminal, reopen it later, specify the same project file, and you can continue right where you left off.

Q: What exactly does the --json flag do?

Without --json, commands output human-readable text descriptions. With --json, the output becomes a structured JSON object containing operation status, document information, and other fields for AI agents or other programs to parse directly.

Q: How can I contribute?

You can fork the repository and submit a Pull Request, or submit registry_entry.json to the CLI-Anything official marketplace to help more users discover the tool.

Q: What open-source license does this project use?

MIT License — free to use, modify, and distribute.