ドキュメントメタデータの抽出
Office 形式はいずれも「コアプロパティ」と呼ばれる共通フィールド(作成者・最終更新日・タイトル・サブジェクト・キーワード)と、形式ごとの拡張フィールドを内包しています。Office Oxide はこれら両方を公開します。
形式と基本情報
Document ハンドルは形式名とカウント(シート数・スライド数・セクション数)を公開します。
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"
コアプロパティ
OOXML 形式では、コアプロパティは docProps/core.xml に格納されています。ネイティブバインディングは型付きの core_properties() アクセサを提供し、Go・C#・C・WASM では統合 JSON IR の metadata ブロックから同じフィールドを読み取ります。
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);
同じ core_properties() アクセサは as_xlsx() および as_pptx() でも利用できます。
拡張(アプリ)プロパティ
docProps/app.xml には拡張メタデータが格納されています。ページ数・単語数・段落数・スライド数・アプリケーション名とバージョン・ハイパーリンクなどが含まれます。
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)
PPTX の場合、app_properties() は slides・notes・presentation_format などを公開します。XLSX の場合はシート名のリストを公開します。
カスタムプロパティ
core_properties() と app_properties() は標準セットを網羅しています。Word の「ドキュメントのプロパティ → 詳細プロパティ」で設定したアプリケーション独自のカスタムキーを取得するには次を使用します。
Python
with Document.open("report.docx") as doc:
custom = doc.as_docx().custom_properties()
for name, value in custom.items():
print(name, value)
レガシー形式
DOC・XLS・PPT は OLE2 の \005SummaryInformation および \005DocumentSummaryInformation ストリームにメタデータを格納しています。Office Oxide はこれらを同じ core_properties() 形式にパースします。
Python
with Document.open("legacy.doc") as doc:
props = doc.as_doc().core_properties()
print(props.author, props.created)
なぜ重要なのか
- 検索インデックス — タイトル・作成者・キーワードがドキュメント検索を支えます。
- コンプライアンス — 最終更新日・作成者・改訂履歴が監査証跡に活用されます。
- 重複排除 — 作成者+タイトル+作成日は低コストながら効果的なフィンガープリントになります。
- PII の削除 — 公開前にコアプロパティを確認し、
EditableDocumentでクリアします。