Office-Dokumente nach Markdown konvertieren
Jedes Office-Oxide-Handle hat eine to_markdown()-Methode, die GitHub-flavored Markdown liefert — Überschriften, Tabellen, Listen und codeähnliche Blöcke — aus jedem der sechs unterstützten Formate. Das ist der richtige Einstiegspunkt für die meisten LLM- und RAG-Pipelines.
Einmaliger Aufruf
Rust
use office_oxide::to_markdown;
let md = to_markdown("report.docx")?;
std::fs::write("report.md", md)?;
Python
import office_oxide
md = office_oxide.to_markdown("report.docx")
open("report.md", "w").write(md)
JavaScript
import { toMarkdown } from 'office-oxide';
import { writeFileSync } from 'node:fs';
writeFileSync('report.md', toMarkdown('report.docx'));
Go
md, err := officeoxide.ToMarkdown("report.docx")
os.WriteFile("report.md", []byte(md), 0o644)
C#
File.WriteAllText("report.md", OfficeOxide.ToMarkdown("report.docx"));
C
int err = 0;
char *md = office_to_markdown("report.docx", &err); /* open + render in one call */
if (md) {
FILE *f = fopen("report.md", "w");
fputs(md, f);
fclose(f);
office_oxide_free_string(md);
}
Wiederverwendbares Handle
Rust
let doc = office_oxide::Document::open("deck.pptx")?;
let md = doc.to_markdown();
Python
from office_oxide import Document
with Document.open("deck.pptx") as doc:
md = doc.to_markdown()
JavaScript
using doc = Document.open('deck.pptx');
const md = doc.toMarkdown();
C
int err = 0;
OfficeDocumentHandle *doc = office_document_open("deck.pptx", &err);
if (doc) {
char *md = office_document_to_markdown(doc, &err);
if (md) { /* use md */ office_oxide_free_string(md); }
office_document_free(doc);
}
WASM
import { WasmDocument } from 'office-oxide-wasm';
// WASM has no file I/O — read the bytes yourself, then open from bytes
const data = new Uint8Array(await (await fetch('/deck.pptx')).arrayBuffer());
using doc = new WasmDocument(data, 'pptx');
const md = doc.toMarkdown();
Was ausgegeben wird
| Quellelement | Markdown |
|---|---|
DOCX-Überschrift (<w:pStyle w:val="Heading1"/> …) |
# Heading (Ebene gemäß Stil) |
| DOCX-Absatz | Ein Absatz, Soft-Hyphens entfernt |
| DOCX-Listenpunkt | - item oder 1. item (Nummerierung erhalten) |
| DOCX-Tabelle | GFM-Pipe-Tabelle |
| XLSX-Tabellenblatt | ## Sheet name + Pipe-Tabelle pro Bereich |
| Verbundene XLSX-Zellen | Inhalt der ersten Zelle, Span wird verworfen |
| PPTX-Folie | ## Slide N + Body, Notizen als Blockquote angehängt |
| PPTX-Tabelle | GFM-Pipe-Tabelle inline in der Folie |
| Hyperlinks | [text](url) |
| Bilder | Platzhalter  — siehe „Bilder" unten |
Bilder
to_markdown() gibt Bilder als Dateiname-Platzhalter aus (z. B. ), extrahiert aber keine Bild-Bytes — Markdown ist ein Textformat. Um Bilder herauszuholen, nutze die IR oder den formatspezifischen Zugriff:
from office_oxide import Document
with Document.open("report.docx") as doc:
ir = doc.to_ir()
for section in ir["sections"]:
for el in section["elements"]:
if el["kind"] == "Image":
print(el["filename"], len(el["data"]))
Vollständiges Schema unter IR-Extraktion.
Einsatzbereiche
- RAG-Ingestion — Markdown ist das LLM-freundlichste Eingabeformat. Ein Durchlauf pro Dokument, deterministische Struktur, kein HTML-Rauschen.
- Dokument-Indexierung — Überschriften liefern natürliche Chunk-Grenzen; Tabellen bleiben abfragbar.
- Migrationen — DOCX → Markdown für Static-Site-Generatoren (Hugo, Astro, MkDocs).
- Content-Diffs — Markdown-Diffs sind wesentlich übersichtlicher als binäre
.docx-Diffs.
Performance
to_markdown() läuft in derselben Größenordnung wie plain_text() — üblicherweise 1–2× Kosten beim Mediandokument. Vollständige Zahlen unter Performance.
Siehe auch
- HTML-Extraktion — wenn stilisierte Ausgabe gefragt ist
- IR-Extraktion — strukturiertes JSON für komplexere Pipelines
- PDF for RAG — Begleitbibliothek
pdf_oxidefür PDFs