Skip to content

Create Documents from IR

create_from_ir writes a brand-new DOCX, XLSX, or PPTX from a DocumentIR — the same structured schema you get out of to_ir(). One IR, three target formats. The IR is the natural sink for LLM-generated content: produce structured JSON, then materialize the right Office format on demand.

Build and write

Rust

use office_oxide::{DocumentFormat};
use office_oxide::create::create_from_ir;
use office_oxide::ir::{DocumentIR, Section, Element, Run};

let ir = DocumentIR {
    sections: vec![Section {
        title: Some("Quarterly Report".into()),
        elements: vec![
            Element::Heading { level: 1, text: "Highlights".into() },
            Element::Paragraph { runs: vec![Run::plain("Revenue grew 18%.")] },
            Element::Table {
                rows: vec![
                    vec!["Region".into(), "Revenue".into()],
                    vec!["NA".into(),     "$1.2M".into()],
                    vec!["EU".into(),     "$820K".into()],
                ],
            },
        ],
    }],
};

create_from_ir(&ir, DocumentFormat::Docx, "report.docx")?;

Switch the target format and you get an XLSX or PPTX from the same IR:

create_from_ir(&ir, DocumentFormat::Xlsx, "report.xlsx")?;
create_from_ir(&ir, DocumentFormat::Pptx, "report.pptx")?;

Python

from office_oxide import create_from_ir

ir = {
    "sections": [{
        "title": "Quarterly Report",
        "elements": [
            {"kind": "Heading", "level": 1, "text": "Highlights"},
            {"kind": "Paragraph", "runs": [{"text": "Revenue grew 18%."}]},
            {"kind": "Table", "rows": [
                ["Region", "Revenue"],
                ["NA",     "$1.2M"],
                ["EU",     "$820K"],
            ]},
        ],
    }],
}

create_from_ir(ir, "docx", "report.docx")
create_from_ir(ir, "xlsx", "report.xlsx")
create_from_ir(ir, "pptx", "report.pptx")

JavaScript

import { createFromIr } from 'office-oxide';

const ir = {
  sections: [{
    title: 'Quarterly Report',
    elements: [
      { kind: 'Heading', level: 1, text: 'Highlights' },
      { kind: 'Paragraph', runs: [{ text: 'Revenue grew 18%.' }] },
      { kind: 'Table', rows: [
        ['Region', 'Revenue'],
        ['NA',     '$1.2M'],
        ['EU',     '$820K'],
      ]},
    ],
  }],
};

createFromIr(ir, 'docx', 'report.docx');
createFromIr(ir, 'xlsx', 'report.xlsx');
createFromIr(ir, 'pptx', 'report.pptx');

Go

Go accepts the IR as a JSON payload:

import (
    "encoding/json"
    officeoxide "github.com/yfedoseev/office_oxide/go"
)

ir := map[string]any{
    "sections": []any{
        map[string]any{
            "title": "Quarterly Report",
            "elements": []any{
                map[string]any{"kind": "Heading", "level": 1, "text": "Highlights"},
                map[string]any{"kind": "Paragraph", "runs": []any{map[string]any{"text": "Revenue grew 18%."}}},
                map[string]any{"kind": "Table", "rows": [][]string{
                    {"Region", "Revenue"},
                    {"NA", "$1.2M"},
                    {"EU", "$820K"},
                }},
            },
        },
    },
}
payload, _ := json.Marshal(ir)

officeoxide.CreateFromIR(string(payload), "docx", "report.docx")
officeoxide.CreateFromIR(string(payload), "xlsx", "report.xlsx")
officeoxide.CreateFromIR(string(payload), "pptx", "report.pptx")

C#

using OfficeOxide;
using System.Text.Json;

var ir = new {
    sections = new[] {
        new {
            title = "Quarterly Report",
            elements = new object[] {
                new { kind = "Heading", level = 1, text = "Highlights" },
                new { kind = "Paragraph", runs = new[] { new { text = "Revenue grew 18%." } } },
                new { kind = "Table", rows = new[] {
                    new[] { "Region", "Revenue" },
                    new[] { "NA",     "$1.2M" },
                    new[] { "EU",     "$820K" },
                }},
            },
        },
    },
};

var payload = JsonSerializer.Serialize(ir);
OfficeOxide.CreateFromIr(payload, "docx", "report.docx");
OfficeOxide.CreateFromIr(payload, "xlsx", "report.xlsx");
OfficeOxide.CreateFromIr(payload, "pptx", "report.pptx");

How each target format renders the IR

IR element DOCX XLSX PPTX
Section Word section break Worksheet (one section → one sheet) Slide
Heading { level } Paragraph w/ Heading{level} style Bold cell at row top Slide title placeholder
Paragraph Body paragraph Cells in successive rows Body text placeholder
List { ordered, items } Numbered or bulleted list Cells in column A Body bullets
Table { rows } Word table Cells starting at the next free row PowerPoint table
Image { filename, data } Inline image (skipped — XLSX needs anchor coords) Slide image

The mapping is conservative: every IR element produces deterministic output, but each format has features the IR doesn’t model (XLSX merges, PPTX animations, DOCX comment threads). For richer output, use the format-specific builders.

Round-trip — read, modify, write

Combine to_ir() with create_from_ir to do structural edits that survive across formats:

from office_oxide import Document, create_from_ir

with Document.open("legacy.doc") as doc:
    ir = doc.to_ir()

# Append a new section
ir["sections"].append({
    "title": "Appendix",
    "elements": [
        {"kind": "Heading", "level": 2, "text": "Updated terms"},
        {"kind": "Paragraph", "runs": [{"text": "Effective 2026-04-19."}]},
    ],
})

create_from_ir(ir, "docx", "modernized.docx")

This is also the cleanest way to do legacy → OOXML conversion (DOC → DOCX, XLS → XLSX, PPT → PPTX). See Conversion: legacy → OOXML.

Why use the IR for creation

  • Format-agnostic templates. Generate the same content as DOCX (for Word users), XLSX (for analysts), or PPTX (for presentations) with no rewriting.
  • LLM-native. Have the model produce JSON matching the IR schema; materialize the file. Far more reliable than asking it to emit Office XML directly.
  • Diffable. IR is JSON; commit it. The Office file becomes a build artifact.

Limitations

  • Images in Element::Image are written when the target format supports inline images (DOCX, PPTX). XLSX requires anchor coordinates, which the simple IR doesn’t carry — skip or use the format-specific builder.
  • Cell formatting (number formats, currency, bold) isn’t part of the IR. Add it via the per-format editor after creation.
  • Charts, smart art, and embedded objects aren’t part of the IR.

For everything beyond the IR’s expressive range, drop into format-specific builders (docx::create::DocxBuilder, xlsx::create::XlsxBuilder, pptx::create::PptxBuilder). They give you full access to OOXML features at the cost of being format-specific.

See also