For AI agents: the complete documentation index is available at https://anyformat.swc.rs/llms.txt, the full documentation bundle is available at https://anyformat.swc.rs/llms-full.txt, and this page is available as Markdown at https://anyformat.swc.rs/api/office.md.

Office

The office document family identifies office document formats from the leading bytes of a file.

LanguagePackageModule
Node.js@swc/anyformat-office@swc/anyformat-office
Pythonanyformat-officeanyformat_office

Supported formats

IdentifierMIME typeFormat
docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentOffice Open XML word processing document
xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetOffice Open XML spreadsheet
pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentationOffice Open XML presentation
odtapplication/vnd.oasis.opendocument.textOpenDocument text document
odsapplication/vnd.oasis.opendocument.spreadsheetOpenDocument spreadsheet
odpapplication/vnd.oasis.opendocument.presentationOpenDocument presentation
cfbapplication/x-cfbCompound File Binary, the container of legacy .doc, .xls, and .ppt files
rtfapplication/rtfRich Text Format

detect

Identifies the office document format of data from its leading bytes. Returns null in Node.js and None in Python when the format is not recognized.

For the ZIP-based formats, data must contain the local file headers up to the first entry that identifies the format. Office applications write that entry near the start of the file, so the first few kilobytes are usually enough.

Node.js

function detect(data: Uint8Array): DetectedFormat | null
import { readFile } from 'node:fs/promises'
import { detect } from '@swc/anyformat-office'

detect(await readFile('report.docx'))
// => { format: 'docx', mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }

Python

def detect(data: bytes) -> DetectedFormat | None
from pathlib import Path

import anyformat_office

anyformat_office.detect(Path("report.docx").read_bytes())
# => DetectedFormat(format='docx', mime_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document')

DetectedFormat

A format identified by detect.

Node.jsPythonTypeDescription
formatformatstringThe stable lowercase identifier of the format, for example "docx".
mimeTypemime_typestringThe most common MIME type of the format.

In Python, DetectedFormat is a final class with read-only properties, and the type of each property is str.

supportedFormats

Returns the identifier of each format that detect can return.

Node.js

function supportedFormats(): string[]
import { supportedFormats } from '@swc/anyformat-office'

supportedFormats()
// => ['docx', 'xlsx', 'pptx', 'odt', 'ods', 'odp', 'cfb', 'rtf']

Python

def supported_formats() -> list[str]
import anyformat_office

anyformat_office.supported_formats()
# => ['docx', 'xlsx', 'pptx', 'odt', 'ods', 'odp', 'cfb', 'rtf']