officetext

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package officetext extracts plain/markdown text natively from DOCX, PPTX and XLSX files - no external service required. It exists so the read_file tool (and seshat-ai's upload/RAG ingestion paths) don't have to depend on docling-serve for formats that are just zipped XML: DOCX and PPTX share an OOXML document-tree shape (word/document.xml, ppt/slides/slideN.xml), so both walk the same generic tree in tree.go. XLSX is a distinct enough format (rows/columns/shared strings/formulas) that it's handled by excelize instead (see xlsx.go).

Index

Constants

View Source
const MaxXLSXRows = 2000

MaxXLSXRows bounds how many rows of one sheet are written. A sheet can hold a million rows of data, which is not something to put in front of a reader as markdown; the rows past the limit are counted, not dropped silently, so the reader knows there is more and can ask for it with a tool that queries the data.

View Source
const MinCharsPerSlide = 40

MinCharsPerSlide is the threshold below which a PPTX's extracted text is treated as "not really there" relative to how many slides the deck has - mirrors pdftext.MinCharsPerPage's reasoning, sized up to account for the "## Slide N\n\n" heading markup Extract itself writes per slide (~13 chars) even when a slide renders no real content. A deck that's mostly screenshots/diagrams with only a slide title or two of real text will parse "successfully" (ok=true, err=nil) but still be nearly useless as a text extraction - callers should treat Sparse the same way they already treat pdftext's Sparse: prefer OCR (a document reader) instead of trusting it.

Variables

View Source
var ErrEmpty = fmt.Errorf("no extractable text found")

ErrEmpty is returned by format extractors when the document parsed successfully but yielded no extractable text (e.g. an image-only slide deck) - callers can use this to decide whether to still try documentreader.

View Source
var SupportedExtensions = map[string]bool{
	".docx": true,
	".pptx": true,
	".xlsx": true,
}

SupportedExtensions lists the formats this package can extract without any external service. Kept as the single source of truth for "is this a native-office format" checks - see internal/tools/files/read/detector.go.

Functions

func Extract

func Extract(filename string, data []byte) (markdown string, ok bool, sparse bool, err error)

Extract dispatches to the format-specific extractor based on filename extension. ok is false when the extension isn't one this package handles; callers should fall back to another conversion path (a document reader) in that case rather than treating it as an error. sparse is only ever true for PPTX (see MinCharsPerSlide) - DOCX/XLSX have no page/slide-count concept to measure sparseness against, and are essentially never image-only.

func ExtractDOCX

func ExtractDOCX(data []byte) (string, error)

ExtractDOCX converts a Word document to markdown: headings (whatever language the styles are named in), paragraphs, bulleted and numbered lists with the numbers Word writes from the list ("3.2"), tables with their merged cells, hyperlinks, footnotes, the alternative text of pictures, the text in text boxes, and code. What it leaves out is what is not the document's own text: headers and footers (the same line on every page), comments, tracked deletions, and the pictures themselves.

func ExtractPPTX

func ExtractPPTX(data []byte) (markdown string, slideCount int, err error)

ExtractPPTX converts a slide deck to markdown: one "## Slide N" section per slide, with the slide's title promoted to a heading, bullets with their depth, tables with their merged cells, charts as tables of their data, the description of pictures, the text of SmartArt diagrams, and the speaker notes. Slide order follows the presentation's slide list (ppt/presentation.xml's sldIdLst, resolved through the rels part), not filename sort: a deck whose slides were reordered after the files were first created would come out in the wrong order.

slideCount is the deck's total slide count (including slides that render to nothing, e.g. a slide that is entirely a picture) - the caller (officetext.Extract) uses it to flag decks whose extracted text is sparse relative to how many slides actually exist, not just whether it is literally empty.

func ExtractXLSX

func ExtractXLSX(data []byte) (string, error)

ExtractXLSX converts every visible sheet of a workbook to markdown, in workbook order. Values are written as the workbook shows them (a date as a date, a percentage as a percentage, a formula as its last calculated value, which is what a user with the workbook open sees), merged cells repeat their value over the cells they cover, a sheet with several blocks of data separated by blank rows becomes several tables, and a title line above a table becomes its caption. Hidden sheets are skipped: they are usually lookup data, not the content.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL