office

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package office converts Word, Excel and PowerPoint files to GitHub-flavored Markdown, so that Read can return them as text. It covers the zip-based formats Office has written since 2007: .docx, .xlsx and .pptx, their macro-enabled and template variants, and .ppsx.

Everything under this directory except this file, office_test.go, model/log.go and NOTICE.md is copied from docstomd-go (https://github.com/m7medVision/docstomd-go, commit e81e9a43bdde, 28 September 2026), which is a Go port of the office converters in Firecrawl's anydoc. On the 94 documents both were tried on, the output was byte-for-byte identical to anydoc's. Only the office packages were taken; docstomd-go's PDF and OCR code, about 40,000 lines, was not.

The changes made to the copy:

  • import paths point here;
  • the parsers log through model.Log rather than slog's default logger;
  • the docx tests read the two fixture files they need from formats/docx/testdata rather than upstream's top-level fixture directory, and the opc test that walks that directory skips without it.

To take a newer upstream version, copy internal/{formats,opc,model,render} over these directories (leaving out formats/office_bench_test.go), rewrite the import prefix github.com/m7medVision/docstomd-go/internal/ to github.com/kvit-s/kvit-coder/internal/office/, and reapply the changes above.

Index

Constants

This section is empty.

Variables

View Source
var ErrEncrypted = errors.New("the document is password-protected")

ErrEncrypted is returned for a password-protected document. Office stores these in a different container from the unprotected kind, so they are recognised but cannot be read.

View Source
var ErrNotOffice = errors.New("not a Word, Excel or PowerPoint file")

ErrNotOffice is returned for a file that is none of the formats this package reads, including zip-based formats that share the Office container, such as .vsdx, .xps and NuGet packages.

Functions

func InspectPackage

func InspectPackage(path string) (isPackage bool, xmlBytes int64)

InspectPackage reports whether the file at path is a zip archive laid out as an Office package, and how many bytes of XML it holds once unpacked. It reads only the archive's directory, so a large zip that is something else is turned away without being read.

The XML size is what predicts the memory a conversion needs: measured on spreadsheets, peak memory ran at 11 to 19 times it, against up to 126 times the file's size. Pictures and other media are left out of the count, since a presentation is often mostly images and costs little to convert.

func IsEncrypted

func IsEncrypted(data []byte) bool

IsEncrypted reports whether data is a password-protected Office document.

func ReadFile

func ReadFile(path string, maxBytes int64) ([]byte, error)

ReadFile reads a file for Convert, refusing one larger than maxBytes before reading it, since the conversion holds the whole file in memory.

Types

type Result

type Result struct {
	Markdown string
	// Kind names the format for a reader, such as "Word document".
	Kind string
	// Warnings lists parts of the document the parser skipped because they
	// were damaged or referred to something missing. The Markdown is complete
	// apart from those parts.
	Warnings []string
}

Result is one converted document.

func Convert

func Convert(data []byte, name string) (result Result, err error)

Convert turns an Office document into Markdown. The format is decided from the content; name is consulted for its extension only when the content does not settle it.

Directories

Path Synopsis
Package formats identifies document formats from content bytes.
Package formats identifies document formats from content bytes.
docx
Package docx converts WordprocessingML packages into the document model: package parts, then the style and numbering models, then spec-order property resolution over the body, notes and drawings.
Package docx converts WordprocessingML packages into the document model: package parts, then the style and numbering models, then spec-order property resolution over the body, notes and drawings.
omml
Package omml converts Office Math (m:oMath) trees, shared by WordprocessingML and PresentationML, into LaTeX math for the model.
Package omml converts Office Math (m:oMath) trees, shared by WordprocessingML and PresentationML, into LaTeX math for the model.
ooxml
Package ooxml holds the content extraction the office frontends share: text cleaning, target and media classification, and the textual content of DrawingML charts and SmartArt.
Package ooxml holds the content extraction the office frontends share: text cleaning, target and media classification, and the textual content of DrawingML charts and SmartArt.
pptx
Package pptx converts PresentationML packages to the document model: slides in presentation order through the full text cascade, with speaker notes quoted after each slide.
Package pptx converts PresentationML packages to the document model: slides in presentation order through the full text cascade, with speaker notes quoted after each slide.
xlsx
Package xlsx converts SpreadsheetML workbooks (.xlsx, .xlsm) to the document model: visible sheets in order, each a table of cell values formatted through their number formats, with hidden rows, columns and sheets omitted and merges remapped onto the surviving grid.
Package xlsx converts SpreadsheetML workbooks (.xlsx, .xlsm) to the document model: visible sheets in order, each a table of cell values formatted through their number formats, with hidden rows, columns and sheets omitted and merges remapped onto the surviving grid.
Package model is the intermediate representation office-format frontends produce and the GFM renderer consumes.
Package model is the intermediate representation office-format frontends produce and the GFM renderer consumes.
Package opc reads ZIP-based OOXML packages under fixed resource limits: part access, content types, relationships with OPC target resolution, and a namespace-aware XML tree.
Package opc reads ZIP-based OOXML packages under fixed resource limits: part access, content types, relationships with OPC target resolution, and a namespace-aware XML tree.
render
gfm
Package gfm serializes the document model to GitHub-Flavored Markdown.
Package gfm serializes the document model to GitHub-Flavored Markdown.

Jump to

Keyboard shortcuts

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