lmoffice guide
Architecture, document-as-code workflows, Open XML layout rules, and the standard lmcode_std_v3 library for lmoffice.
Overview
lmoffice packages Microsoft's Open XML SDK (DocumentFormat.OpenXml 3.5.1) and the lmcode runtime into a single .NET 8 NativeAOT executable with three format-specific subcommands: docx, xlsx, and pptx. Each subcommand embeds its own schema and exposes a root factory context alongside the built-in lmcode_std_v3 standard library, while the shared inspect subcommand validates generated packages with OpenXmlValidator and extracts JSON summaries or canonical Markdown.
Subcommand architecture and format contexts
Because Word, Excel, and PowerPoint have distinct object models, lmoffice separates them into dedicated CLI routes so each _lmcode_ block compiles against a focused schema:
- Word processing route (cli="lmoffice docx"): exposes context docx: DocxHost. Calling docx.create(path) returns a Docx builder that owns paragraphs, headings, lists, clauses, signature lines, tables, headers, footers, section breaks, and table-of-contents fields.
- Spreadsheet route (cli="lmoffice xlsx"): exposes context xlsx: XlsxHost. Calling xlsx.create(path) returns an Xlsx workbook builder that creates Sheet handles for cell population, formulas, number and font styling, freeze panes, autofilters, data validation, conditional formatting, and charts.
- Presentation route (cli="lmoffice pptx"): exposes context pptx: PptxHost. Calling pptx.create(path) returns a Pptx deck builder that manages theme colors and creates Slide and PptxTable handles on a 1280x720 pixel canvas at 96 DPI.
- Cross-format workflows: a single LMScript program can combine multiple _lmcode_ blocks targeting different lmoffice routes (for example, computing a quarterly summary in outer LMScript and writing both an Excel workbook and an executive Word memo).
Documents as code: Markdown and XHTML/CSS profiles
In addition to fine-grained builder calls, lmoffice supports declarative document-as-code authoring across all three formats:
- Markdown to Office: Docx.markdown(text) and Docx.markdown_file(path) render headings, bold and italic spans, bullet and numbered lists, tables, blockquotes, and directives such as {{sign: Name}} into Word paragraphs and tables. Pptx.markdown(text) splits slide-separated Markdown into presentation slides, while Xlsx.sheet_from_markdown_table(name, text) and Xlsx.sheet_from_csv(name, text) create typed worksheets.
- Round-trip extraction: DocxHost.to_markdown(path), XlsxHost.to_markdown(path), PptxHost.to_markdown(path), and the CLI command lmoffice inspect FILE --markdown read existing Office packages back into canonical Markdown.
- XHTML and CSS profiles: Docx.html_doc(xml, css) implements the additive html-doc@1 and css-doc@1 contract supporting article and div containers, h1 through h3, p, span, strong, em, br, flat ul and ol lists, rectangular tables, local PNG/JPEG images, HTTP/HTTPS/mailto links, and @page geometry (Letter or A4 with four margins). The legacy Docx.html_xml(xml, css) method remains available for html-subset@1 and css-subset@1 templates.
content = "<article xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Quarterly update</h1><p>Capacity is <strong>stable</strong>.</p></article>";
styles = "<style xmlns=\"urn:lmctl:css:1\"><rule select=\"p\"><set name=\"margin-bottom\" value=\"6pt\"/></rule></style>";
p = _lmcode_ cli="lmoffice docx" install="github:lmctl-ai/lmoffice@v0.1.33";
let d = docx.create("update.docx");
d.html_doc(${content}, ${styles});
d.save();
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));
Coordinate conventions and layout rules
- 1-based table and cell indexing: Word Table methods (cell, shade, paragraph, merge, cell_border, column_width), Excel Sheet methods (set, formula, bold, fill, merge, border, chart anchor cells), and PowerPoint PptxTable methods all use 1-based row and column numbers.
- Points vs pixels: Word page dimensions, margins, paragraph spacing, indents, tab stops, and font sizes are measured in points (72 points per inch). PowerPoint slide shapes, text boxes, images, tables, and charts use pixels on a 1280x720 canvas at 96 DPI.
- Colors and alignments: hex colors use six hexadecimal digits (with or without a leading #), and paragraph or cell alignments accept left, center, right, or justify.
- Self-contained sample images: docx.sample_image(path), xlsx.sample_image(path), and pptx.sample_image(path) write a deterministic 64x64 PNG on disk so examples and tests can embed artwork without external image assets.
Standard lmcode_std_v3 library
All three format registries include the standard lmcode_std_v3 catalog of string, math, collection (IntList, FloatList, StrList, IntMap, FloatMap, StrMap, stacks, queues, priority queues), JSON, template, file, and return-framing functions. The REST and CLI handler interfaces of newer lmcode_std_v3 catalogs are not documented for this host; check lmoffice docx --lmcode-signatures on the installed release before relying on them.