> 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

Entry point for Word document operations — returns a fluent WordDocument builder

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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
