-
Notifications
You must be signed in to change notification settings - Fork 107
command get
zmworm edited this page Mar 31, 2026
·
23 revisions
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 |
| 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 |
The get command returns a DocumentNode tree. The output varies depending on whether --json is used.
Each node is printed with its path, type, text preview (truncated to 60 characters), style name, and child count. Attributes are listed as indented key-value pairs, and children are displayed recursively.
{path} ({Type}) "text content truncated to 60 chars" [StyleName] ({N} children)
key: value
key: value
{child.path} ({child.Type}) "text"
key: value
Example:
/body/p[1] (Paragraph) "Introduction to the document which may be..." [Heading1] (3 children)
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
- 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.28