> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-word/word.md).

# Built-In Functions

The `word()` BIF is the primary entry point for all Word document operations. It returns a `WordDocument` instance that supports fluent method chaining.

## Method Signature

```js
word( [file], [text], [html], [markdown] )
```

## Arguments

| Argument   | Type   | Required | Default | Description                                             |
| ---------- | ------ | -------- | ------- | ------------------------------------------------------- |
| `file`     | String | No       | —       | Path to an existing `.docx` file to open and modify     |
| `text`     | String | No       | —       | Plain text content to populate the document with        |
| `html`     | String | No       | —       | HTML string to parse and populate the document with     |
| `markdown` | String | No       | —       | Markdown string to parse and populate the document with |

{% hint style="info" %}
When no arguments are provided, a new empty document is created. When multiple content arguments are provided (e.g., `text` and `html`), the content is appended in argument order.
{% endhint %}

## Returns

A `WordDocument` instance — a fluent builder that supports method chaining.

***

## Examples

### Create a New Empty Document

```js
doc = word()
doc.addHeading( "My Report", 1 )
doc.addParagraph( "Hello world!" )
doc.save( "report.docx" )
```

### Open an Existing Document

```js
doc = word( "/path/to/template.docx" )
doc.replaceText( "[DATE]", "2024-06-15" )
doc.save( "/path/to/filled.docx" )
```

### Create from Plain Text

```js
word( text="Hello World\n\nParagraph two" )
    .save( "from-text.docx" )
```

### Create from Markdown

```js
word( markdown="## Introduction\n\n**Bold** and *italic* text." )
    .save( "from-markdown.docx" )
```

### Create from HTML

```js
word( html="<h1>Title</h1><p>Paragraph with <b>bold</b> text.</p>" )
    .save( "from-html.docx" )
```

### Combined Arguments

```js
word( file="/templates/base.docx", markdown="## Appended Section\n\nExtra content." )
    .save( "combined.docx" )
```

### Full Fluent Chain

```js
word( "/path/to/report.docx" )
    .margins( 1.78, 1.78, 1.78, 1.78 )
    .pageSize( "A4" )
    .header( "Confidential" )
    .addHeading( "Q4 Report", 1 )
    .addParagraph( "Executive summary..." )
    .addTable( salesDataQuery )
    .addPageBreak()
    .addHeading( "Details", 2 )
    .addParagraph( "Detailed breakdown..." )
    .save()
```

***

## Related

{% content-ref url="/pages/RXgrFl2M6vqh1dMUnLI1" %}
[Fluent API](/boxlang-+-++/modules/bx-word/fluent-api.md)
{% endcontent-ref %}

{% content-ref url="<https://github.com/ortus-boxlang/boxlang-docs/tree/v1.x/boxlang-framework/boxlang-plus/user-guide.md>" %}
<https://github.com/ortus-boxlang/boxlang-docs/tree/v1.x/boxlang-framework/boxlang-plus/user-guide.md>
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-word/word.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
