Word +
A powerful BoxLang module for creating, reading, populating, and converting Word documents with a fluent, chainable API
Last updated
Was this helpful?
Was this helpful?
box install bx-word// Build a document from scratch
word( "/path/to/report.docx" )
.margins( 1.78, 1.78, 1.78, 1.78 )
.addHeading( "My Report", 1 )
.addParagraph( "Hello World" )
.addTable( [ [ "Name", "Role" ], [ "John Doe", "Engineer" ] ] )
.save()// Open an existing template and fill placeholders
word( "/templates/contract.docx" )
.populate( { name: "John Doe", date: "2024-01-01" } )
.save( "/output/contract.docx" )// The word() BIF accepts text, markdown, and html arguments directly
word( text="Hello World\n\nParagraph two" )
.save( "from-text.docx" )
word( markdown="## Title\n\nParagraph with **bold** text." )
.save( "from-markdown.docx" )
word( html="<h1>Title</h1><p>Hello <b>World</b></p>" )
.save( "from-html.docx" )// Build and convert in one chain
doc = word().addHeading( "Report", 1 ).addParagraph( "Content" )
plainText = doc.toText() // plain text
markdown = doc.toMarkdown() // markdown with YAML front matter
html = doc.toHTML() // HTML with inline styles + base64 images