Skip to content

command get

zmworm edited this page Apr 19, 2026 · 47 revisions

get

Get a document node by its DOM path.

Synopsis

officecli get <file> [path] [--depth N] [--json]

Description

Retrieves a document element at the specified path, returning its properties and optionally its children. Read-only.

Arguments

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

Options

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.

Output Format

The get command returns a DocumentNode tree. The output varies depending on whether --json is used.

Text Output (default)

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

JSON Output (--json)

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).

DocumentNode Fields

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)

Output

For each node:

  • Path: DOM path to the element
  • Type: Element type name
  • Attributes: Key-value properties
  • Children: Child elements (up to --depth levels)

Format-Specific References

selected Pseudo-Path

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 2

Returns 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.

Notes

  • 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).

See Also


Based on OfficeCLI v1.0.53

Clone this wiki locally