Skip to content

Markdown から Office ドキュメントを作成する

create_from_markdown は、単一の Markdown 文字列 から DOCX・XLSX・PPTX を新規作成します。1 つの Markdown ソースで 3 つの出力形式に対応します。Markdown は LLM が生成するコンテンツの自然な出力先です。モデルに Office XML を直接出力させるよりも Markdown を出力させる方がはるかに安定しており、必要な Office 形式にオンデマンドで変換できます。

内部では Markdown が Office Oxide の構造化 DocumentIR へ解析され、ターゲット形式にレンダリングされます。そのため、同一の決定論的かつ形式非依存なマッピングが得られます。IR 自体は主に抽出・検査用のインターフェイスです(to_ir() を参照)。作成については、すべてのバインディングでの公開エントリポイントは Markdown です。

create_from_markdown のシグネチャは?

この関数は Markdown 文字列、ターゲット形式("docx""xlsx""pptx"、大文字小文字不問)、および出力パスを受け取ります。成功時は何も返さず、失敗時はエラーを返すか例外を発生させます。

バインディング シグネチャ
Python def create_from_markdown(markdown: str, format: str, path, /) -> None
Rust pub fn create_from_markdown(markdown: &str, format: DocumentFormat, path: impl AsRef<Path>) -> Result<()>
Go func CreateFromMarkdown(markdown, format, path string) error
JavaScript createFromMarkdown(markdown, format, path)
C# static void Document.CreateFromMarkdown(string markdown, string format, string path)

Markdown から DOCX・XLSX・PPTX を作成するには?

コンテンツを一度 Markdown で記述し、format 引数を切り替えてターゲット形式を選択します。

Rust

use office_oxide::create::create_from_markdown;
use office_oxide::format::DocumentFormat;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let markdown = "\
# Quarterly Report

Generated automatically from Markdown using Office Oxide.

## Highlights

- Revenue grew by **32%** year-over-year
- Customer satisfaction: 4.8 / 5.0

## Financial Summary

| Category   | Q3 2025 | Q4 2025 |
|------------|---------|---------|
| Revenue    | $1.2M   | $1.6M   |
| Net Profit | $0.4M   | $0.7M   |
";

    create_from_markdown(markdown, DocumentFormat::Docx, "report.docx")?;
    create_from_markdown(markdown, DocumentFormat::Xlsx, "report.xlsx")?;
    create_from_markdown(markdown, DocumentFormat::Pptx, "report.pptx")?;
    Ok(())
}

Python

from office_oxide import create_from_markdown

markdown = """\
# Quarterly Report

Generated automatically from Markdown using Office Oxide.

## Highlights

- Revenue grew by **32%** year-over-year
- Customer satisfaction: 4.8 / 5.0
- New products launched: Widget Pro, Widget Lite

## Financial Summary

| Category   | Q3 2025 | Q4 2025 |
|------------|---------|---------|
| Revenue    | $1.2M   | $1.6M   |
| Expenses   | $0.8M   | $0.9M   |
| Net Profit | $0.4M   | $0.7M   |
"""

# One Markdown source, three target formats:
create_from_markdown(markdown, "docx", "report.docx")
create_from_markdown(markdown, "xlsx", "report.xlsx")
create_from_markdown(markdown, "pptx", "report.pptx")

JavaScript

import { createFromMarkdown } from 'office-oxide';

const markdown = `# Quarterly Report

Generated automatically from Markdown using Office Oxide.

## Highlights

- Revenue grew by **32%** year-over-year
- Customer satisfaction: 4.8 / 5.0

## Financial Summary

| Category   | Q3 2025 | Q4 2025 |
|------------|---------|---------|
| Revenue    | $1.2M   | $1.6M   |
| Net Profit | $0.4M   | $0.7M   |
`;

for (const fmt of ['docx', 'xlsx', 'pptx']) {
  createFromMarkdown(markdown, fmt, `report.${fmt}`);
}

Go

package main

import (
    "log"

    oo "github.com/yfedoseev/office_oxide/go"
)

func main() {
    markdown := `# Quarterly Report

Generated automatically from Markdown using Office Oxide.

## Highlights

- Revenue grew by **32%** year-over-year
- Customer satisfaction: 4.8 / 5.0

## Financial Summary

| Category   | Q3 2025 | Q4 2025 |
|------------|---------|---------|
| Revenue    | $1.2M   | $1.6M   |
| Net Profit | $0.4M   | $0.7M   |
`

    for _, fmt := range []string{"docx", "xlsx", "pptx"} {
        if err := oo.CreateFromMarkdown(markdown, fmt, "report."+fmt); err != nil {
            log.Fatalf("CreateFromMarkdown(%s): %v", fmt, err)
        }
    }
}

C#

using OfficeOxide;

const string markdown = """
    # Quarterly Report

    Generated automatically from Markdown using Office Oxide.

    ## Highlights

    - Revenue grew by **32%** year-over-year
    - Customer satisfaction: 4.8 / 5.0

    ## Financial Summary

    | Category   | Q3 2025 | Q4 2025 |
    |------------|---------|---------|
    | Revenue    | $1.2M   | $1.6M   |
    | Net Profit | $0.4M   | $0.7M   |
    """;

foreach (var fmt in new[] { "docx", "xlsx", "pptx" })
{
    Document.CreateFromMarkdown(markdown, fmt, $"report.{fmt}");
}

C

#include <stdio.h>
#include "office_oxide.h"

int main(void) {
    const char *markdown =
        "# Quarterly Report\n\n"
        "Generated automatically from Markdown using Office Oxide.\n\n"
        "## Highlights\n\n"
        "- Revenue grew by **32%** year-over-year\n"
        "- Customer satisfaction: 4.8 / 5.0\n\n"
        "## Financial Summary\n\n"
        "| Category   | Q3 2025 | Q4 2025 |\n"
        "|------------|---------|---------|\n"
        "| Revenue    | $1.2M   | $1.6M   |\n"
        "| Net Profit | $0.4M   | $0.7M   |\n";

    /* format: "docx" | "xlsx" | "pptx" (case-insensitive) */
    const char *formats[] = { "docx", "xlsx", "pptx" };
    for (int i = 0; i < 3; i++) {
        int err = 0;
        char path[32];
        snprintf(path, sizeof(path), "report.%s", formats[i]);
        if (office_create_from_markdown(markdown, formats[i], path, &err) != 0) {
            fprintf(stderr, "create_from_markdown(%s) failed: code=%d\n", formats[i], err);
            return 1;
        }
    }
    return 0;
}

各ターゲット形式での Markdown レンダリング

Markdown は Office Oxide の構造化 IR へ解析され、各形式がその構造を決定論的にレンダリングします。

Markdown の要素 DOCX XLSX PPTX
# 見出し Heading{level} スタイルの段落 セクション先頭の太字セル スライドのタイトルプレースホルダー
段落テキスト 本文段落 連続する行のセル 本文テキストプレースホルダー
- / 1. リスト 箇条書きまたは番号付きリスト 列 A のセル 本文の箇条書き
テーブル Word のテーブル 次の空き行からのセル PowerPoint テーブル
**太字** / *斜体* インラインの文字書式 セルのプレーンテキスト インラインの文字書式

このマッピングは保守的です。すべての Markdown 要素が決定論的な出力を生成しますが、各 Office 形式には Markdown では表現できない機能があります(XLSX のセル数値フォーマット、PPTX のアニメーション、DOCX のコメントスレッドなど)。より豊富な出力が必要な場合は、ファイルを作成した後にフォーマット専用のエディタで編集するか、フォーマット固有のライターを使用してください。

形式をまたいで読み込み・編集・書き出しするには?

抽出と作成を組み合わせると、形式をまたいで内容を編集できます。ソースを Markdown として読み込み、Markdown を変更し、新しいファイルを書き出します。

Python

from office_oxide import Document, create_from_markdown

with Document.open("legacy.doc") as doc:
    markdown = doc.to_markdown()

# Append a new section
markdown += "\n## Appendix\n\nEffective 2026-06-22.\n"

create_from_markdown(markdown, "docx", "modernized.docx")

C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "office_oxide.h"

int main(void) {
    int err = 0;

    /* Read the source as Markdown */
    OfficeDocumentHandle *doc = office_document_open("legacy.doc", &err);
    if (!doc) { fprintf(stderr, "open failed: code=%d\n", err); return 1; }
    char *md = office_document_to_markdown(doc, &err);
    office_document_free(doc);
    if (!md) { fprintf(stderr, "to_markdown failed: code=%d\n", err); return 1; }

    /* Append a new section */
    const char *appendix = "\n## Appendix\n\nEffective 2026-06-22.\n";
    char *modified = malloc(strlen(md) + strlen(appendix) + 1);
    strcpy(modified, md);
    strcat(modified, appendix);
    office_oxide_free_string(md);

    /* Write a fresh file */
    office_create_from_markdown(modified, "docx", "modernized.docx", &err);
    free(modified);
    return err;
}

これは、テキスト構造のみが必要な場合にレガシー形式から OOXML へ移行する(DOC → DOCX、XLS → XLSX、PPT → PPTX)クリーンな方法でもあります。元のレイアウトを保持した構造保存型の変換には、IR を経由してラウンドトリップする save_as() を使用してください。詳細はレガシー → OOXML 変換を参照してください。

なぜ Markdown から Office ファイルを生成するのか?

  • 形式非依存のテンプレート。 同じコンテンツを DOCX(Word ユーザー向け)、XLSX(アナリスト向け)、PPTX(プレゼンテーション向け)として出力できます。書き直しは不要で、format 引数を変えるだけです。
  • LLM ネイティブ。 モデルに Markdown を生成させ、ファイルに変換します。モデルが最も安定して出力できるのが Markdown です。
  • 差分管理が可能。 Markdown はプレーンテキストなのでコミットできます。Office ファイルはビルド成果物になります。
  • 高速。 Office Oxide の Rust コアはミリ秒単位でファイルを書き出し、ベンチマークコーパス全体で 100% のパスレートを達成しています。

上級者向け: DocumentIR から直接ビルドする(Rust)

Rust クレートでは、Markdown を経由せず構造化 IR を手動で構築・変換したい場合に create_from_ir も公開しています。

use office_oxide::create::create_from_ir;
use office_oxide::format::DocumentFormat;
use office_oxide::ir::DocumentIR;

// Build or transform a DocumentIR however you like, then render it:
let ir: DocumentIR = DocumentIR::from_markdown("# Title\n\nBody.\n", DocumentFormat::Docx);
create_from_ir(&ir, DocumentFormat::Docx, "report.docx")?;
pub fn create_from_ir(ir: &DocumentIR, format: DocumentFormat, path: impl AsRef<Path>) -> Result<()>

Python・Go・JavaScript・C# のバインディングでは IR は読み取り専用です。検査やパイプラインには to_ir() で取得し、ファイルの作成には create_from_markdown を使用してください。

制限事項

  • セルの書式設定(数値フォーマット、通貨、カスタムスタイル)は Markdown では表現できません。作成後にフォーマット専用のエディタで追加してください。
  • 画像、グラフ、スマートアート、埋め込みオブジェクトは Markdown パスでは扱えません。これらにはフォーマット固有のライター(XlsxWriterPptxWriter、DOCX ビルダー)を使用してください。
  • XLSX のセル結合、PPTX のアニメーション、DOCX のコメントスレッドには Markdown での表現がありません。

Markdown の表現範囲を超えるものにはフォーマット固有のライターを使用してください。OOXML のすべての機能にアクセスできますが、その代わりに形式固有となります。

よくある質問

create_from_markdown が生成できる形式は? DOCX・XLSX・PPTX です。format 引数は "docx""xlsx""pptx" です(大文字小文字を区別しません)。レガシーバイナリ形式(DOC・XLS・PPT)は読み取り専用であり、作成はできません。

Python や他のバインディングに create_from_ir 関数はありますか? いいえ。create_from_ir は Rust クレートにのみ公開されています。Python・Go・JavaScript・C# では create_from_markdown でファイルを作成してください。IR(to_ir/to_ir_json)は抽出側の読み取り専用の概念です。

既存ドキュメントのレイアウトを保持してラウンドトリップするには? 構造保存型の変換には save_as() を使用してください。テキスト構造のみをきれいに再構築したい場合は to_markdown() + create_from_markdown() を使用してください。

ドキュメント作成の速度は? Office Oxide の Rust コアは Office ファイルをミリ秒単位で書き出し、ベンチマークコーパス全体で 100% のパスレートを達成しています。リクエストハンドラ内でオンデマンドにドキュメントを生成するのに十分な速度です。

関連ドキュメント