Skip to content

문서 메타데이터 추출

모든 Office 형식은 작은 “core properties” 세트(작성자, 마지막 수정 날짜, 제목, 주제, 키워드)와 형식별 확장 세트를 임베드합니다. Office Oxide는 둘 다 노출합니다.

형식과 기본 정보

Document 핸들은 형식 이름과 카운트(시트, 슬라이드, 섹션)를 노출합니다:

Python

from office_oxide import Document

with Document.open("report.docx") as doc:
    print(doc.format)            # "docx"
    print(doc.detect_format())   # 매직 바이트로 확인

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

OOXML 형식의 경우 core properties는 docProps/core.xml에 있습니다. 형식별 접근자로 들어가세요:

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);
}

같은 core_properties() 접근자가 as_xlsx()as_pptx()에도 있습니다.

Go

Go는 통합 JSON IR을 통해 core properties를 노출합니다:

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());

확장(app) properties

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는 시트 이름 목록을 노출합니다.

사용자 정의 properties

core_properties()app_properties()는 표준 세트를 커버합니다. 애플리케이션 정의 사용자 키(Word의 "문서 속성 → 고급 속성"에서 설정)에는:

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() 형태로 파싱합니다:

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

왜 중요한가

  • 검색 인덱싱 — 제목, 작성자, 키워드가 문서 발견을 이끕니다.
  • 컴플라이언스 — 마지막 수정, 생성자, 리비전 이력이 감사 추적에 들어갑니다.
  • 중복 제거 — 작성자 + 제목 + 생성 날짜는 저렴하지만 효과적인 지문입니다.
  • PII 제거 — 게시 전에 core properties를 읽고, EditableDocument로 비우세요.

더 보기