Skip to content

Office 문서 편집

EditableDocumentDocument를 읽고 수정한 뒤 다시 저장할 수 있게 해 주는 짝 API입니다. 변경되지 않은 모든 OPC 파트 — 이미지, 차트, 스타일, 테마, 관계 — 를 그대로 보존하므로 편집이 주변 콘텐츠를 다시 흐르게 하거나 다운스트림 소비자를 무효화하지 않습니다.

편집은 DOCX, XLSX, PPTX에서 지원됩니다. 레거시 DOC, XLS, PPT는 읽기 전용 — 편집이 필요하면 먼저 save_as로 변환하세요.

할 수 있는 것

작업 DOCX XLSX PPTX 메서드
본문/플레이스홀더 텍스트 치환 replace_text
셀 값 설정(문자열/숫자/불리언/빈) set_cell
디스크에 저장 save
바이트로 저장 save_to_bytes

replace_text는 XLSX에서 0을 반환합니다(거기엔 <w:t><a:t> 요소가 없으니까요); 스프레드시트에는 set_cell을 사용하세요.

열고, 편집하고, 저장

Python

from office_oxide import EditableDocument

with EditableDocument.open("template.docx") as ed:
    ed.replace_text("{{name}}", "Alice")
    ed.replace_text("{{date}}", "2026-04-19")
    ed.save("filled.docx")

Rust

use office_oxide::edit::EditableDocument;

let mut ed = EditableDocument::open("template.docx")?;
ed.replace_text("{{name}}", "Alice");
ed.replace_text("{{date}}", "2026-04-19");
ed.save("filled.docx")?;

JavaScript

import { EditableDocument } from 'office-oxide';

using ed = EditableDocument.open('template.docx');
ed.replaceText('{{name}}', 'Alice');
ed.replaceText('{{date}}', '2026-04-19');
ed.save('filled.docx');

Go

ed, err := officeoxide.OpenEditable("template.docx")
defer ed.Close()
ed.ReplaceText("{{name}}", "Alice")
ed.ReplaceText("{{date}}", "2026-04-19")
ed.Save("filled.docx")

C#

using var ed = EditableDocument.Open("template.docx");
ed.ReplaceText("{{name}}", "Alice");
ed.ReplaceText("{{date}}", "2026-04-19");
ed.Save("filled.docx");

바이트로 저장(업로드/스트리밍용)

Python

with EditableDocument.open("template.docx") as ed:
    ed.replace_text("{{name}}", "Alice")
    bytes_out = ed.save_to_bytes()
    # bytes_out을 S3에 업로드 / HTTP로 전송 등

Rust

let mut ed = EditableDocument::open("template.docx")?;
ed.replace_text("{{name}}", "Alice");

let mut buf = std::io::Cursor::new(Vec::new());
ed.write_to(&mut buf)?;
let bytes: Vec<u8> = buf.into_inner();

JavaScript

using ed = EditableDocument.open('template.docx');
ed.replaceText('{{name}}', 'Alice');
const bytes = ed.saveToBytes();   // Uint8Array

"OPC 파트 보존"이 실제로 의미하는 것

OOXML 파일은 수십 개의 XML 파트와 바이너리 파트(이미지, 글꼴, 임베드 객체)를 담은 ZIP 아카이브입니다. 순진한 편집기는 저장할 때 모든 파트를 다시 직렬화하는데, 이는:

  • 관계를 재정렬해 링크를 깨뜨리고
  • 편집기가 이해 못 하는 확장 파트(custom XML, AlternateContent fallback)를 떨어뜨리며
  • 다운스트림 diff와 서명을 망치는 식으로 XML을 다시 포맷합니다

EditableDocument는 당신이 건드린 파트만 다시 씁니다. 나머지는 바이트 단위로 복사됩니다. 결과는 입력과 출력 사이의 가능한 가장 작은 diff — 버전 관리, 서명 검증, 다른 도구로의 round-trip에 친화적입니다.

형식별 API로 가야 할 때

EditableDocument는 80% 사례(템플레이트, 일괄 채우기, 셀 쓰기)를 커버합니다. 더 풍부한 편집 — 단락 추가, 표 삽입, 스타일 조정, 슬라이드를 처음부터 만들기 — 에는 형식별 API로 들어가세요:

use office_oxide::docx::edit::DocxEditor;

let mut docx = DocxEditor::open("report.docx")?;
docx.append_paragraph("새 섹션", Some("Heading2"));
docx.save("report.docx")?;

형식별 편집기는 각 바인딩 레퍼런스(Rust: docx::edit, xlsx::edit, pptx::edit)에 문서화되어 있습니다.

더 보기