Scripting Protocol
VimSheet exposes a JSON-based protocol for external scripts to interact with a running instance.
Communication
Scripts communicate with VimSheet via stdin/stdout using newline-delimited JSON messages.
Communication
Scripts communicate with VimSheet via stdin/stdout using newline-delimited JSON messages (one JSON object per line).
Message format:
{"type": "request", "id": 1, "method": "get_cell", "params": {"sheet": 0, "col": 0, "row": 0}}
Response format:
{"type": "response", "id": 1, "result": {"value": "Hello"}}
Available Methods
Method |
Params |
Description |
|---|---|---|
|
|
Get cell value |
|
|
Set cell value |
|
|
Get range as 2D array |
|
|
Set range from 2D array |
|
|
Evaluate a formula string |
|
|
Execute a |
Using External Scripts
In visual mode, press ! or use the range-prefix syntax to pipe a
selection through an external script:
:A1:B10!/path/to/script.py
Protocol version 1. Newline-delimited JSON on stdin/stdout.
Example
import sys
import json
def request(method, params):
msg = json.dumps({"type": "request", "id": 1, "method": method, "params": params})
sys.stdout.write(msg + "\n")
sys.stdout.flush()
return json.loads(sys.stdin.readline())["result"]
# Get cell A1
value = request("get_cell", {"sheet": 0, "col": 0, "row": 0})
print(f"A1 = {value}")
# Set cell B1 to 42
request("set_cell", {"sheet": 0, "col": 1, "row": 0, "value": 42})