For the complete documentation index, see llms.txt. This page is also available as Markdown.

User Guide

Complete guide to creating, modifying, and exporting Word documents with BoxLang

Comprehensive guide to all features of the BoxLang Word Module.


Core Concepts

The word() BIF

The word() BIF is the primary entry point. It returns a WordDocument instance that supports fluent method chaining:

result = word()                          // new empty document
result = word( "/path/to/file.docx" )    // open existing file
result = word( text="Hello World" )      // create from text
result = word( markdown="## Title" )     // create from Markdown
result = word( html="<h1>Title</h1>" )   // create from HTML

The WordDocument Object

All mutating methods return this, enabling chaining:

word()
    .margins( 1.5, 1.5, 1.5, 1.5 )
    .addHeading( "Title", 1 )
    .addParagraph( "Content" )
    .save( "output.docx" )

Method Chaining Pattern

Every method that modifies the document returns the WordDocument instance. This means you can chain indefinitely:


Creating Documents

From Scratch

Opening Existing Files

From Text Content

From Markdown

From HTML

{% hint style="info" %} Levels are clamped to the range 1–6. Level 0 becomes 1; level 7 becomes 6. {% endhint %}

Paragraphs

Plain paragraphs:

Formatted paragraphs:

Option
Type
Description

bold

Boolean

Bold text

italic

Boolean

Italic text

size

Integer

Font size in points

color

String

Hex color (with or without #)

font

String

Font family name

alignment

String

LEFT, CENTER, RIGHT, JUSTIFY

spacingBefore

Integer

Space before paragraph in twips

spacingAfter

Integer

Space after paragraph in twips

lineSpacing

Integer

Line spacing in twips (240 = single, 360 = 1.5)

firstLineIndent

Integer

First line indent in twips

Page Breaks

Empty Lines


Tables

From a 2-D Array

The first row is automatically bolded as the header:

From a Query

Column names become bold headers:

From a Struct

With explicit headers and data keys:


Lists

Unordered (Bulleted)

Ordered (Numbered)

Nested Lists

Use a struct with text and items keys for sub-lists:

{% hint style="info" %} Nesting supports any depth — sub-items can themselves contain further sub-lists. {% endhint %}


Images

From File Path

From Bytes

From Base64

From URL


Hyperlinks are rendered as blue, underlined text.


Page Setup

Margins

Page Size

Orientation

Headers & Footers

Section Breaks

Create a new section to apply different page setup to subsequent pages:


Template Population

Placeholder Replacement

Replace {{variableName}} patterns with actual values:

Literal Find & Replace

Bookmarks


Saving & Exporting

Save to File

Get as Bytes

Get as Base64

Write to Stream


Document Properties


Fluent Helpers

tap() — Side Effects in Chains

Execute an action without breaking the chain. Useful for logging or debugging:

when() — Conditional Branching

Conditionally execute actions without breaking the fluent chain:


Document Cleanup

The WordDocument implements AutoCloseable. When done, release POI resources:

{% hint style="warning" %} After calling close(), the document is no longer usable.


FormattingImport & ExportAdvanced FeaturesExamplesFluent API

Last updated

Was this helpful?