-
Notifications
You must be signed in to change notification settings - Fork 108
command query
Query document elements using CSS-like selectors.
officecli query <file> <selector> [--json]
Searches the document for elements matching a CSS-like selector expression. Returns all matching elements with their paths and properties. Read-only.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file |
FileInfo | Yes | - | Office document path |
selector |
string | Yes | - | CSS-like selector expression |
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
--json |
bool | No | false |
Output as structured JSON |
| 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] - Color-aware:
[fill=#FF0000]matches[fill=FF0000] - Dimension-aware: compares
2cmvs1incorrectly - Special keys
textandtypematch node content and type -
\!=accepted for zsh compatibility
parent[filter] > child[filter]
Unknown selectors match any XML element by local name (case-insensitive).
The query command returns a list of DocumentNodes matching the selector. The output varies depending on whether --json is used.
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
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.
- Word query - Word selectors and attributes
- Excel query - Excel selectors and attributes
- PowerPoint query - PowerPoint selectors and attributes
- Command Reference
- get - Get specific elements by path
- view - View document content
Based on OfficeCLI v1.0.28