Skip to content

command remove

zmworm edited this page Mar 31, 2026 · 23 revisions

remove

Remove an element from the document.

Synopsis

officecli remove <file> <path>

Description

Removes the element at the specified DOM path from the document. The element and all its children are permanently deleted.

Arguments

Name Type Required Default Description
file FileInfo Yes - Office document path
path string Yes - DOM path of the element to remove (see Path Reference)

Examples

# Remove a paragraph
officecli remove report.docx /body/p[3]

# Remove a table
officecli remove report.docx /body/tbl[1]

# Remove a table row
officecli remove report.docx /body/tbl[1]/tr[2]

# Remove a run from a paragraph
officecli remove report.docx /body/p[1]/r[2]

# Remove a header
officecli remove report.docx /header[1]

# Remove a bookmark
officecli remove report.docx "/bookmark[MyMark]"

# Remove an Excel sheet (by navigating to it)
officecli remove data.xlsx /Sheet2

# Remove a named range
officecli remove data.xlsx /namedrange[1]

# Remove a data validation
officecli remove data.xlsx /Sheet1/validation[1]

# Remove conditional formatting
officecli remove data.xlsx /Sheet1/cf[1]

# Remove a comment
officecli remove data.xlsx /Sheet1/comment[1]

# Remove a shape or picture from a sheet
officecli remove data.xlsx /Sheet1/shape[1]
officecli remove data.xlsx /Sheet1/picture[1]

# Remove a rich text run from a cell
officecli remove data.xlsx /Sheet1/A1/run[2]

# Remove a PowerPoint notes slide
officecli remove slides.pptx /slide[1]/notes

# Remove a PowerPoint slide
officecli remove slides.pptx /slide[3]

# Remove a shape from a slide
officecli remove slides.pptx /slide[1]/shape[2]

# Remove a chart
officecli remove slides.pptx /slide[1]/chart[1]

# Remove an Excel chart
officecli remove data.xlsx /Sheet1/chart[1]

# Remove an Excel table (ListObject)
officecli remove data.xlsx /Sheet1/table[1]

# Remove a Word chart
officecli remove report.docx /chart[1]

# Remove a Word TOC
officecli remove report.docx /toc[1]

# Remove a footnote/endnote
officecli remove report.docx /footnote[1]
officecli remove report.docx /endnote[1]

Notes

  • Removing an element shifts subsequent indices. For example, after removing /body/p[2], the former /body/p[3] becomes /body/p[2].

  • When removing multiple elements, work from highest index to lowest to avoid index shifting issues, or use batch mode.

  • Excel row/column formula warnings: When removing an Excel row or column (/Sheet1/row[N] or /Sheet1/col[A]), the command prints a warning if other cells are affected by the deletion:

    • Cells whose formulas will become #REF! (directly referenced the deleted row/column)
    • Cells with formulas that reference shifted rows/columns (formula text is unchanged but references moved)

    Example warning output:

    Removed /Sheet1/row[5]
    Warning: 3 formula cell(s) affected — 1 cell(s) will become #REF!: B10; 2 cell(s) reference shifted rows/cols (formula text unchanged): A15, C20
    

See Also


Based on OfficeCLI v1.0.28

Clone this wiki locally