Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

command query

zmworm edited this page Jun 8, 2026 · 52 revisions

query

Query document elements using CSS-like selectors.

Synopsis

officecli query <file> <selector> [--find <text>] [--json]

Description

Searches the document for elements matching a CSS-like selector expression. Returns all matching elements with their paths and properties. Read-only.

Arguments

Name Type Required Default Description
file FileInfo Yes - Office document path
selector string Yes - CSS-like selector expression

Options

Name Type Required Default Description
--find string No - Case-insensitive text/value substring filter — hard rename of the legacy --text flag.
--json bool No false Output as structured JSON

Selector Syntax

Attribute Filters

Operator Meaning Example
= Exact match [style=Heading1]
!= Not equal [font!=Arial]
~= Contains text [text~=quarterly]
>= Greater or equal (numeric) [size>=24pt]
<= Less or equal (numeric) [size<=12pt]

Notes:

  • Can combine: shape[fill=FF0000][size>=24pt] (implicit AND)
  • Boolean and / or: cell[value>5000 or value<100], cell[(type=Number or type=Date) and value>0]. Applies to query, set, and remove across all three formats via the shared filter engine.
  • Has-attribute exists: [link] matches any element where the attribute is present and non-empty.
  • Excel row-by-column-name: Sheet1!row[Salary>5000] matches rows where the named column's value satisfies the predicate (also works on detected header-row tables). OR'd table-column predicates inside row[...] fail loud, never silent.
  • Color-aware: [fill=#FF0000] matches [fill=FF0000]
  • Dimension-aware: compares 2cm vs 1in correctly
  • Special keys text and type match node content and type
  • \!= accepted for zsh compatibility

Child Selector

parent[filter] > child[filter]

Generic XML Fallback

Unknown selectors match any XML element by local name (case-insensitive).

Output Format

The query command returns a list of DocumentNodes matching the selector. The output varies depending on whether --json is used.

Text Output (default)

The text output starts with a match count, followed by each matching node listed with its path, text content, and formatting attributes.

Matches: {count}
 /body/p[1]: Heading text
 style: Heading1
 alignment: center
 /body/p[3]: Another paragraph
 style: Normal

Example:

Matches: 3
 /body/p[1]: Introduction
 style: Heading1
 alignment: center
 font: Arial
 /body/p[4]: Chapter One
 style: Heading1
 alignment: left
 /body/p[9]: Chapter Two
 style: Heading1
 alignment: left

JSON Output (--json)

With --json, the output is an object containing the match count and an array of DocumentNode results.

{
 "Matches": 3,
 "Results": [
 {
 "Path": "/body/p[1]",
 "Type": "Paragraph",
 "Text": "Introduction",
 "Preview": null,
 "Style": "Heading1",
 "ChildCount": 1,
 "Format": {
 "alignment": "center",
 "font": "Arial"
 },
 "Children": []
 },
 {
 "Path": "/body/p[4]",
 "Type": "Paragraph",
 "Text": "Chapter One",
 "Preview": null,
 "Style": "Heading1",
 "ChildCount": 1,
 "Format": {
 "alignment": "left"
 },
 "Children": []
 }
 ]
}

Each element in the Results array is a DocumentNode with the same fields as described in get Output Format: Path, Type, Text, Preview, Style, ChildCount, Format, and Children.

Format-Specific References

See Also


Based on OfficeCLI v1.0.105

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /