Skip to content

command get

zmworm edited this page Mar 31, 2026 · 23 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

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

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

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

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

Clone this wiki locally