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");
C
int err = 0;
char *text = office_extract_text("report.docx", &err);
if (text) {
printf("%s\n", text);
office_oxide_free_string(text);
}
재사용 가능한 핸들
텍스트뿐만 아니라 다른 출력(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();
C
int err = 0;
OfficeDocumentHandle *doc = office_document_open("report.docx", &err);
if (!doc) { fprintf(stderr, "open failed: code=%d\n", err); return 1; }
char *text = office_document_plain_text(doc, &err);
char *md = office_document_to_markdown(doc, &err);
/* use text / md ... */
office_oxide_free_string(text);
office_oxide_free_string(md);
office_document_free(doc);
형식별 출력 내용
| 형식 | 출력 |
|---|---|
| DOCX | 문서 순서대로 본문 텍스트 + 머리글/바닥글; 소프트 하이픈 제거 |
| XLSX | 모든 시트의 셀 값, 행 안에서는 탭 구분, 시트 사이에는 빈 줄 |
| PPTX | 슬라이드 제목, 본문 자리 표시자, 표 셀, 노트 — 슬라이드마다 하나의 단락 블록 |
| DOC | DOCX와 동일한 구조 — CFB piece-table에서 직접 파싱 |
| XLS | XLSX와 동일한 구조 — BIFF8 레코드에서 직접 파싱 |
| PPT | PPTX와 동일한 구조 — PowerPoint Document 스트림에서 파싱 |
바이트에서 읽기 (임시 파일 불필요)
서버리스 및 스트리밍 파이프라인에서 유용합니다.
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();
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());
C
/* format must be one of: "docx" "xlsx" "pptx" "doc" "xls" "ppt" (lowercase) */
int err = 0;
OfficeDocumentHandle *doc =
office_document_open_from_bytes(data, len, "docx", &err);
if (doc) {
char *text = office_document_plain_text(doc, &err);
if (text) { printf("%s\n", text); office_oxide_free_string(text); }
office_document_free(doc);
}
WASM
import { WasmDocument } from 'office-oxide-wasm';
const res = await fetch('https://example.com/report.docx');
const data = new Uint8Array(await res.arrayBuffer());
using doc = new WasmDocument(data, 'docx');
console.log(doc.plainText());
성능
| 형식 | 평균 | 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에서 구조화된 행 추출