-
Notifications
You must be signed in to change notification settings - Fork 190
command get
Get a document node by its DOM path.
officecli get <file> [path] [--depth N] [--json]
Retrieves a document element at the specified path, returning its properties and optionally its children. Read-only.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file |
FileInfo | Yes | - | Office document path |
path |
string | No | / |
DOM path to the element, or selected to query currently-selected elements in watch preview |
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
--depth |
int | No | 1 |
Depth of child nodes to include. 0 = node only, 1 = immediate children. |
--json |
bool | No | false |
Output as structured JSON |
--save |
string | No | - | For OLE objects: extract embedded binary to the specified file path. Returns savedTo and savedBytes. |
The get command returns a DocumentNode tree. The output varies depending on whether --json is used.
Each node is printed as a single-line, grep-friendly record: path, type, quoted text, and all attributes as key=value pairs. Children are printed as separate lines (one per node, recursively). This format is designed for piping to grep, awk, or jq -R.
{path} ({type}) "text" children=N style=X key=val key=val ...
Example:
/body/p[1] (Paragraph) "Introduction to the document which may be..." children=3 style=Heading1 alignment=center font=Arial
/body/p[1]/r[1] (Run) "Introduction" bold=true size=14
With --json, the output is wrapped in a standard envelope:
{
"success": true,
"data": {
"Path": "/body/p[1]",
"Type": "Paragraph",
"Text": "paragraph text",
"Preview": null,
"Style": "Heading1",
"ChildCount": 3,
"Format": {
"alignment": "center",
"font": "Arial",
"size": "14"
},
"Children": [
{
"Path": "/body/p[1]/r[1]",
"Type": "Run",
"Text": "Introduction",
"Preview": null,
"Style": null,
"ChildCount": 0,
"Format": {
"bold": "true",
"size": "14"
},
"Children": []
}
]
}
}On error, the envelope returns "success": false with structured error details (see JSON Error Envelope).
| Field | Type | Description |
|---|---|---|
Path |
string | DOM path to the element (e.g., /body/p[1]) |
Type |
string | Element type name (e.g., Paragraph, Run, Table, Cell) |
Text |
string | Text content of the node (full text in JSON, truncated to 60 chars in text mode) |
Preview |
string or null | Preview content for non-text nodes (e.g., image descriptions) |
Style |
string or null | Style name applied to the element (e.g., Heading1, Normal) |
ChildCount |
int | Total number of direct child elements |
Format |
object | Dictionary of formatting attributes as key-value string pairs |
Children |
array | Recursive list of child DocumentNode objects (depth-limited by --depth) |
For each node:
- Path: DOM path to the element
- Type: Element type name
- Attributes: Key-value properties
-
Children: Child elements (up to
--depthlevels)
- Word get - Word paths and examples
- Excel get - Excel paths and examples
- PowerPoint get - PowerPoint paths and examples
When a watch process is running, you can query the elements currently selected in the browser preview:
# Returns an array of DocumentNode objects for all selected elements
officecli get slides.pptx selected
officecli get slides.pptx selected --json
officecli get slides.pptx selected --depth 2Returns an empty array if nothing is selected, or an error if no watch process is running. Click elements (or drag a rubber-band box) in the browser preview to select.
- The root path
/returns different information per format:- Word: Document metadata (title, author, etc.) and page setup
- Excel: List of all sheets with row/column counts
- PowerPoint: Presentation metadata and slide list
- Path indices are 1-based (XPath convention).
- Command Reference
- query - Find elements by selector
- set - Modify element properties
Based on OfficeCLI v1.0.53