Skip to content

Dokument-Metadaten extrahieren

Jedes Office-Format beinhaltet einen kleinen Satz „Kerneigenschaften" — Autor, letztes Änderungsdatum, Titel, Thema, Stichwörter — plus einen formatspezifischen Erweiterungssatz. Office Oxide macht beide zugänglich.

Format und Basisinformationen

Das Document-Handle liefert den Formatnamen sowie Zähler (Tabellenblätter, Folien, Abschnitte):

Rust

use office_oxide::{Document, DocumentFormat};

let doc = Document::open("report.docx")?;
assert_eq!(doc.format(), DocumentFormat::Docx);

Python

from office_oxide import Document

with Document.open("report.docx") as doc:
    print(doc.format)            # "docx"
    print(doc.detect_format())   # confirms via magic bytes

JavaScript

using doc = Document.open('report.docx');
console.log(doc.format);        // "docx"

Go

doc, err := officeoxide.Open("report.docx")
if err != nil { log.Fatal(err) }
defer doc.Close()

fmtName, _ := doc.Format()   // "docx"
fmt.Println(fmtName)

C#

using OfficeOxide;

using var doc = Document.Open("report.docx");
Console.WriteLine(doc.Format);   // "docx"

C

int err = 0;
OfficeDocumentHandle *doc = office_document_open("report.docx", &err);
if (!doc) { fprintf(stderr, "open failed: code=%d\n", err); return 1; }
const char *fmt = office_document_format(doc);   /* "docx" — do NOT free */
printf("%s\n", fmt);
office_document_free(doc);

WASM

import { WasmDocument } from 'office-oxide-wasm';

const data = new Uint8Array(await (await fetch('/report.docx')).arrayBuffer());
using doc = new WasmDocument(data, 'docx');
console.log(doc.formatName());   // "docx"

Kerneigenschaften

Bei OOXML-Formaten liegen die Kerneigenschaften in docProps/core.xml. Die nativen Bindings stellen einen typisierten core_properties()-Accessor bereit; Go, C#, C und WASM lesen dieselben Felder aus dem metadata-Block des vereinheitlichten JSON IR.

Rust

use office_oxide::Document;

let doc = Document::open("report.docx")?;
if let Some(docx) = doc.as_docx() {
    let props = docx.core_properties();
    println!("{:?}", props.title);
    println!("{:?}", props.author);
}

Python

from office_oxide import Document

with Document.open("report.docx") as doc:
    docx = doc.as_docx()
    props = docx.core_properties()
    print(props.title)            # str | None
    print(props.author)           # str | None
    print(props.created)          # datetime | None
    print(props.modified)         # datetime | None
    print(props.subject)          # str | None
    print(props.keywords)         # str | None

Go

doc, _ := officeoxide.Open("report.docx")
defer doc.Close()

irJSON, _ := doc.ToIRJSON()
var ir struct {
    Metadata struct {
        Title    string `json:"title"`
        Author   string `json:"author"`
        Created  string `json:"created"`
        Modified string `json:"modified"`
        Subject  string `json:"subject"`
        Keywords string `json:"keywords"`
    } `json:"metadata"`
}
json.Unmarshal([]byte(irJSON), &ir)
fmt.Println(ir.Metadata.Title, ir.Metadata.Author)

C#

using OfficeOxide;
using System.Text.Json;

using var doc = Document.Open("report.docx");
using var ir = JsonDocument.Parse(doc.ToIrJson());

var meta = ir.RootElement.GetProperty("metadata");
Console.WriteLine(meta.GetProperty("title").GetString());
Console.WriteLine(meta.GetProperty("author").GetString());
Console.WriteLine(meta.GetProperty("created").GetString());

C

int err = 0;
OfficeDocumentHandle *doc = office_document_open("report.docx", &err);
char *ir_json = office_document_to_ir_json(doc, &err);   /* DocumentIR as JSON */
if (ir_json) {
    /* parse with your JSON lib; read ir["metadata"]["title"], ["author"], ... */
    office_oxide_free_string(ir_json);
}
office_document_free(doc);

WASM

import { WasmDocument } from 'office-oxide-wasm';

const data = new Uint8Array(await (await fetch('/report.docx')).arrayBuffer());
using doc = new WasmDocument(data, 'docx');
const meta = doc.toIr().metadata;          // JS object
console.log(meta.title, meta.author, meta.created);

Denselben core_properties()-Accessor gibt es auch auf as_xlsx() und as_pptx().

Erweiterte App-Eigenschaften

docProps/app.xml enthält erweiterte Metadaten: Seitenanzahl, Wörteranzahl, Absätze, Folienanzahl, App-Name und Version, Hyperlinks usw.

Python

with Document.open("report.docx") as doc:
    app = doc.as_docx().app_properties()
    print(app.application)   # "Microsoft Office Word"
    print(app.app_version)
    print(app.pages)
    print(app.words)
    print(app.paragraphs)

Für PPTX liefert app_properties() slides, notes, presentation_format usw. Für XLSX die Liste der Blattnamen.

Benutzerdefinierte Eigenschaften

core_properties() und app_properties() decken die Standardsätze ab. Für anwendungsdefinierte Schlüssel (in Word über „Dokumenteigenschaften → Erweiterte Eigenschaften" gesetzt) verwende:

Python

with Document.open("report.docx") as doc:
    custom = doc.as_docx().custom_properties()
    for name, value in custom.items():
        print(name, value)

Veraltete Formate

DOC, XLS und PPT speichern Metadaten in den OLE2-Streams \005SummaryInformation und \005DocumentSummaryInformation. Office Oxide parst sie in dieselbe core_properties()-Struktur:

Python

with Document.open("legacy.doc") as doc:
    props = doc.as_doc().core_properties()
    print(props.author, props.created)

Warum das wichtig ist

  • Suchindexierung — Titel, Autor und Stichwörter ermöglichen die Dokumentensuche.
  • Compliance — Letzte Änderung, Ersteller und Revisionsverlauf fließen in Prüfprotokolle ein.
  • Deduplizierung — Autor + Titel + Erstelldatum ist ein günstiger, aber wirksamer Dokumenten-Fingerabdruck.
  • Entfernung persönlicher Daten — Kerneigenschaften vor der Veröffentlichung auslesen und anschließend mit EditableDocument löschen.

Siehe auch