문서 메타데이터 추출
모든 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)
왜 중요한가
- 검색 인덱싱 — 제목, 작성자, 키워드가 문서 검색 가능성을 높입니다.
- 컴플라이언스 — 최종 수정 날짜, 작성자, 수정 이력이 감사 추적의 기반이 됩니다.
- 중복 제거 — 작성자 + 제목 + 생성 날짜는 저렴하지만 효과적인 문서 지문입니다.
- 개인정보 제거 — 공개 전에 핵심 속성을 확인하고,
EditableDocument로 값을 지웁니다.