Skip to content

Format-agnostic IR

DocumentIR is Office Oxide’s structural bridge between formats. Open a .docx, a .xlsx, or a legacy .ppt and you get the same shape back: a list of sections, each with a sequence of typed elements (headings, paragraphs, tables, lists, images).

The IR powers to_html, save_as, and legacy → OOXML conversion. It is also the right surface for downstream pipelines — search indexes, RAG chunkers, custom renderers — because you process one schema instead of six format-specific ones.

Read the IR

Rust

use office_oxide::Document;

let doc = Document::open("report.docx")?;
let ir = doc.to_ir();

for section in &ir.sections {
    println!("{:?}", section.title);
    for el in &section.elements {
        // el is an Element enum — Heading, Paragraph, Table, List, Image, ...
    }
}

Python

from office_oxide import Document

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

for section in ir["sections"]:
    print(section.get("title"))
    for el in section["elements"]:
        kind = el["kind"]   # "Heading" | "Paragraph" | "Table" | "List" | "Image"

JavaScript

using doc = Document.open('report.docx');
const ir = doc.toIr();

for (const section of ir.sections) {
  for (const el of section.elements) {
    // el.kind: "Heading" | "Paragraph" | "Table" | "List" | "Image"
  }
}

Go

import "encoding/json"

irJSON, _ := doc.ToIRJSON()

var ir struct {
    Sections []struct {
        Title    *string           `json:"title"`
        Elements []json.RawMessage `json:"elements"`
    } `json:"sections"`
}
_ = json.Unmarshal([]byte(irJSON), &ir)

C#

using System.Text.Json;

using var doc = Document.Open("report.docx");
using var ir = JsonDocument.Parse(doc.ToIrJson());

foreach (var section in ir.RootElement.GetProperty("sections").EnumerateArray())
{
    // ...
}

Schema

The shape is deliberately small and stable.

{
  "sections": [
    {
      "title": "Optional section title",     // string | null
      "elements": [
        { "kind": "Heading", "level": 1, "text": "..." },
        { "kind": "Paragraph", "runs": [
            { "text": "Hello ", "bold": false, "italic": false },
            { "text": "world", "bold": true,  "italic": false }
        ] },
        { "kind": "List", "ordered": true, "items": ["one", "two"] },
        { "kind": "Table", "rows": [
            ["A1", "B1"],
            ["A2", "B2"]
        ] },
        { "kind": "Image", "filename": "image1.png", "data": "<base64>" }
      ]
    }
  ]
}

Per-format mapping:

Format Section boundary Notes
DOCX One section per <w:sectPr> (or whole body if none) Headings keyed by w:pStyle
XLSX One section per worksheet title = sheet name; one Table element per used range
PPTX One section per slide title = slide title placeholder; notes attached as a final paragraph
DOC / XLS / PPT Same shape as their OOXML counterparts Parsed via the legacy CFB pipeline

Why use the IR

  • Build once, render many. Convert DOCX, XLSX, and PPTX into the same shape, run a single search/chunking pipeline.
  • LLM context that survives format changes. Schema doesn’t drift when source documents move from .doc to .docx.
  • Round-trip with save_as. Edit the IR, then write a new document of any supported format.
use office_oxide::create::create_from_ir;
use office_oxide::DocumentFormat;

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

Serializing

The Rust DocumentIR derives Serialize / Deserialize (via serde). Python’s to_ir() returns a plain dict (already JSON-serializable). The Node, Go, C#, and C bindings expose JSON strings via to_ir_json() / ToIRJSON() / ToIrJson().

See also