Office 문서에서 텍스트 추출
Office Oxide는 단일 진입점 — extract_text()(또는 Document.open(...).plain_text()) — 으로 DOCX, XLSX, PPTX, DOC, XLS, PPT 모두에 대해 동일하게 작동합니다. 형식별 코드 분기가 필요 없습니다.
한 줄 호출
가장 빠른 방법: 함수 한 번 호출로 파일을 열고, 형식에 맞는 추출기를 돌리고, 문자열을 반환합니다.
Rust
use office_oxide::extract_text;
let text = extract_text("report.docx")?;
println!("{text}");
Python
import office_oxide
text = office_oxide.extract_text("report.docx")
print(text)
JavaScript
import { extractText } from 'office-oxide';
console.log(extractText('report.docx'));
Go
import officeoxide "github.com/yfedoseev/office_oxide/go"
text, err := officeoxide.ExtractText("report.docx")
C#
using OfficeOxide;
string text = OfficeOxide.ExtractText("report.docx");
재사용 가능한 핸들
텍스트뿐 아니라 다른 출력(Markdown, HTML, IR)도 필요하면 문서를 한 번 열고 핸들을 재사용하세요:
Rust
use office_oxide::Document;
let doc = Document::open("report.docx")?;
let text = doc.plain_text();
let md = doc.to_markdown();
Python
from office_oxide import Document
with Document.open("report.docx") as doc:
text = doc.plain_text()
md = doc.to_markdown()
JavaScript
import { Document } from 'office-oxide';
using doc = Document.open('report.docx');
const text = doc.plainText();
const md = doc.toMarkdown();
형식별 출력
| 형식 | 출력 |
|---|---|
| DOCX | 문서 순서의 본문 + 머리글/바닥글; 소프트 하이픈 제거 |
| XLSX | 각 시트의 셀 값, 행 안에서는 탭 구분, 시트 사이에는 빈 줄 |
| PPTX | 슬라이드 제목, 본문 자리표시자, 표 셀, 노트 — 슬라이드별 단락 블록 |
| DOC | DOCX와 같은 형태 — CFB piece-table에서 직접 파싱 |
| XLS | XLSX와 같은 형태 — BIFF8 레코드에서 직접 파싱 |
| PPT | PPTX와 같은 형태 — PowerPoint Document 스트림에서 파싱 |
바이트에서 (임시 파일 불필요)
서버리스, 스트리밍 파이프라인에서 유용합니다.
Python
import requests
from office_oxide import Document
data = requests.get("https://example.com/report.docx").content
with Document.from_bytes(data, "docx") as doc:
print(doc.plain_text())
JavaScript
import { Document } from 'office-oxide';
const res = await fetch('https://example.com/report.docx');
const data = new Uint8Array(await res.arrayBuffer());
using doc = Document.fromBytes(data, 'docx');
console.log(doc.plainText());
Rust
use std::io::Cursor;
use office_oxide::{Document, DocumentFormat};
let data = std::fs::read("report.docx")?;
let doc = Document::from_reader(Cursor::new(data), DocumentFormat::Docx)?;
let text = doc.plain_text();
성능
| 형식 | 평균 | p99 | 통과율 |
|---|---|---|---|
| DOCX (2,538 파일) | 0.8ms | 3.9ms | 98.9% |
| XLSX (1,802 파일) | 5.0ms | 40ms | 97.8% |
| PPTX (806 파일) | 0.7ms | 3.9ms | 98.4% |
| DOC (246 파일) | 0.3ms | 3.4ms | 94.7% |
| XLS (494 파일) | 2.8ms | 75ms | 99.2% |
| PPT (176 파일) | 0.7ms | 6.6ms | 100% |
전체 벤치마크 방법론은 성능 참고.
더 보기
- Markdown 추출 — 같은 API, GitHub Flavored 출력
- HTML 추출 — 미리보기/임베드용 시맨틱 HTML
- 형식 무관 IR — 파이프라인과 LLM용 구조화 JSON
- 표 — XLSX, DOCX, PPTX에서 구조화된 행 추출