# How to Extract Plain Text from a Document Using OfficeCLI

> Extract plain text from Word, PowerPoint, or Excel with OfficeCLI. Stream clean text without the Office UI using the simple get command. Try it now!

- Repository: [OfficeAI/OfficeCLI](https://github.com/iofficeai/OfficeCLI)
- Tags: how-to-guide
- Published: 2026-07-09

---

**Use the `officecli get <file> --format text` command (or the `-t` shorthand) to stream clean plain text from Word, PowerPoint, or Excel documents without loading the Office UI.**

The **iOfficeAI/OfficeCLI** repository provides a cross-platform command-line tool that parses Microsoft Office Open XML files directly. If you need to **extract plain text from a document using OfficeCLI**, the tool offers a built-in `get` command that bypasses formatting markup and outputs only the readable content from `.docx`, `.pptx`, and `.xlsx` files.

## Command-Line Syntax for Text Extraction

OfficeCLI exposes text extraction through the `get` verb combined with the `--format text` option. When invoked, the CLI routes the request to a format-specific handler that parses the underlying XML structure and returns a concatenated string.

The basic invocation pattern is:

```bash
officecli get <file-path> --format text

```

For convenience, use the short alias `-t`:

```bash
officecli get report.docx -t

```

## How OfficeCLI Extracts Text Internally

According to the iOfficeAI/OfficeCLI source code, the extraction logic differs by document type. The tool utilizes the **Open XML SDK** (referenced in `src/officecli/officecli.csproj`) to read document parts without loading them into the Office application.

### Word Document Processing

For `.docx` files, the implementation resides in [`src/officecli/Handlers/Word/WordHandler.View.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Handlers/Word/WordHandler.View.cs). The handler walks the `<w:p>` (paragraph) and `<w:r>` (run) hierarchy defined in the Open XML specification. It aggregates text content from these elements while explicitly discarding drawing objects, styles, field codes, and other non-text nodes.

### PowerPoint Presentation Processing

For `.pptx` files, [`src/officecli/Handlers/Pptx/PowerPointHandler.Query.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Handlers/Pptx/PowerPointHandler.Query.cs) manages the operation. It targets `<a:t>` elements—text runs inside shapes—and concatenates them in slide order. When you pass the `--format text` flag, the query method returns the visible text content of each slide, respecting the original reading order and inserting line breaks between slides.

## Practical Code Examples

You can integrate OfficeCLI into shell scripts and automation pipelines to process documents in bulk.

Extract text to stdout:

```bash
officecli get contract.docx --format text

```

Redirect output to a text file:

```bash
officecli get presentation.pptx -t > slides.txt

```

Batch process an entire directory of Word documents:

```bash
for file in *.docx; do
    officecli get "$file" -t > "${file%.docx}.txt"
done

```

The Node.js SDK documented in [`sdk/node/README.md`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/README.md) mirrors this behavior, allowing JavaScript consumers to invoke the same extraction routines programmatically via the wrapper API.

## Summary

- Use `officecli get <file> -t` to extract plain text from Word, PowerPoint, or Excel documents.
- Word extraction walks the `<w:p>`/`<w:r>` hierarchy in [`WordHandler.View.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/WordHandler.View.cs).
- PowerPoint extraction collects `<a:t>` elements via [`PowerPointHandler.Query.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/PowerPointHandler.Query.cs).
- The tool leverages the Open XML SDK and supports both .NET and Node.js environments.

## Frequently Asked Questions

### Does OfficeCLI preserve formatting like bold or italics when extracting text?

No. The plain-text extraction intentionally strips all presentation markup, including styles, fonts, colors, and hyperlinks. It returns only the raw character content in reading order.

### Can I extract text from password-protected documents?

No. OfficeCLI cannot decrypt protected files. You must remove document protection or provide decrypted copies before using the `get` command.

### Is there a way to extract text from a specific section only?

Yes. Combine the `--path` selector with the text format flag. For example, `officecli get doc.docx --path "/document/body/sectPr[1]" -t` extracts text only from the first section of a Word document.

### Does the tool support legacy .doc or .ppt formats?

No. OfficeCLI only supports Open XML formats (`.docx`, `.pptx`, `.xlsx`). Legacy binary formats are not handled by the current handler implementations in the repository.