Skip to content

Office 문서를 HTML로 변환

Office Oxide의 모든 핸들에는 to_html() 메서드가 있어, 지원되는 어떤 형식에서든 깨끗한 시맨틱 HTML5를 만듭니다. 브라우저 미리보기, 이메일 렌더링, 간단한 시각적 diff에 적합합니다.

원샷

Python

import office_oxide

html = office_oxide.to_html("report.docx")
open("report.html", "w").write(html)

Rust

use office_oxide::to_html;

let html = to_html("report.docx")?;
std::fs::write("report.html", html)?;

JavaScript

import { toHtml } from 'office-oxide';
import { writeFileSync } from 'node:fs';

writeFileSync('report.html', toHtml('report.docx'));

Go

html, err := officeoxide.ToHTML("report.docx")
os.WriteFile("report.html", []byte(html), 0o644)

C#

File.WriteAllText("report.html", OfficeOxide.ToHtml("report.docx"));

재사용 가능한 핸들

Python

from office_oxide import Document

with Document.open("slides.pptx") as doc:
    html = doc.to_html()

JavaScript

using doc = Document.open('slides.pptx');
const html = doc.toHtml();

Rust

let doc = office_oxide::Document::open("slides.pptx")?;
let html = doc.to_html();

실제 출력

출력은 fragment 형태<html>, <head>, <body> 래퍼가 없습니다. 어디에 마운트할지, 어떤 스타일시트를 쓸지는 사용자가 결정합니다.

소스 HTML 요소
제목 소스 레벨에 맞는 <h1><h6>
단락 <p>
굵게 / 기울임 / 밑줄 <strong>, <em>, <u>
목록 <li> 자식이 있는 <ul> / <ol>
<table> 안에 <thead>, <tbody>, <tr>, <th>, <td>
하이퍼링크 <a href="...">
이미지 <img src="..." alt="...">
XLSX 시트 <section data-sheet="이름"> + <table>
PPTX 슬라이드 <section data-slide="N"> + 본문 + 노트용 선택적 <aside>

출력은 이스케이프됩니다: 문서 안의 사용자 콘텐츠는 HTML 이스케이프되므로 결과를 페이지에 임베딩해도 기본적으로 안전합니다.

독립 페이지로 감싸기

from office_oxide import Document

with Document.open("report.docx") as doc:
    body = doc.to_html()

page = f"""<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>리포트</title>
<link rel="stylesheet" href="docs.css">
</head><body>{body}</body></html>"""

open("report.html", "w").write(page)

사용 사례

  • 업로드된 문서를 브라우저에서 미리보기 (<input type="file"> → WASM → <iframe srcdoc>).
  • 생성된 리포트의 이메일 렌더링.
  • diff 뷰 — HTML diff은 코드 리뷰 도구에서 의미 있게 렌더됩니다.
  • 구조를 보존한 검색 인덱싱(제목으로 결과 부스팅 가능).

더 보기