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 ¶
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 (docling) instead of trusting it.
Variables ¶
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 docling.
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 ¶
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 (e.g. docling) 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 ¶
ExtractDOCX converts a Word document's body (paragraphs, headings, tables) to markdown. Embedded images, headers/footers and tracked-changes markup are not rendered - callers that need those still have docling available.
func ExtractPPTX ¶
ExtractPPTX converts a slide deck to markdown: one "## Slide N" section per slide, with the slide's title (if any) promoted to a heading and other text placeholders/tables rendered below it. Slide order follows the presentation's actual slide order (ppt/presentation.xml's sldIdLst, resolved through the rels part), not filename sort - a deck whose slides were reordered after slideN.xml files were first created would otherwise 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's entirely an image with no text shapes) - 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's literally empty.
func ExtractXLSX ¶
ExtractXLSX converts every sheet of a workbook to a markdown table, in workbook sheet order. Formulas are rendered as their last calculated value (excelize's GetRows resolves cached results, matching what a user would see with the workbook open), not as the formula text.
Types ¶
This section is empty.