Dokument-Metadaten extrahieren
Jedes Office-Format bringt einen kleinen Satz „Core Properties" mit — Autor, letztes Änderungsdatum, Titel, Thema, Stichwörter — plus einen formatspezifischen Erweiterungssatz. Office Oxide stellt beide bereit.
Format & Basisinfo
Das Document-Handle nennt Format-Namen und Zähler (Sheets, Folien, Abschnitte):
Python
from office_oxide import Document
with Document.open("report.docx") as doc:
print(doc.format) # "docx"
print(doc.detect_format()) # bestätigt per Magic-Bytes
Rust
use office_oxide::{Document, DocumentFormat};
let doc = Document::open("report.docx")?;
assert_eq!(doc.format(), DocumentFormat::Docx);
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"
Core Properties
Bei OOXML-Formaten leben die Core Properties in docProps/core.xml. Steig in den formatspezifischen Accessor:
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
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);
}
Den gleichen core_properties()-Accessor gibt es auf as_xlsx() und as_pptx().
Go
Go stellt Core Properties über die einheitliche JSON-IR bereit:
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());
Erweiterte (App-)Properties
docProps/app.xml enthält erweiterte Metadaten: Seiten, Wörter, Absätze, Folien, 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 exposed app_properties() slides, notes, presentation_format etc.; für XLSX die Liste der Sheet-Namen.
Custom Properties
core_properties() und app_properties() decken die Standardsätze ab. Für anwendungsdefinierte eigene Keys (in Word über „Dokumenteigenschaften → Erweiterte Eigenschaften" gesetzt) nimm:
with Document.open("report.docx") as doc:
custom = doc.as_docx().custom_properties()
for name, value in custom.items():
print(name, value)
Legacy-Formate
DOC, XLS und PPT speichern Metadaten in den OLE2-Streams \005SummaryInformation und \005DocumentSummaryInformation. Office Oxide parst sie in dieselbe core_properties()-Form:
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 treiben Document Discovery.
- Compliance — Last-Modified, Ersteller und Revisionsverlauf füttern Audit-Trails.
- Deduplication — Autor + Titel + Erstelldatum ist ein billiger, aber wirksamer Fingerprint.
- PII entfernen — vor der Veröffentlichung Core Properties auslesen und mit
EditableDocumentleeren.
Siehe auch
- Strukturierte IR — Inhaltsextraktion
- Editieren — Überblick — Properties beim Speichern ändern