# Microsoft Word (DOCX)

Use this page when you want to design the document in Microsoft Word and generate a true `.docx` output from Salesforce data.

A DOCX template is built in Word, then uploaded to S-Docs for generation.

Use it when Word layout tools matter more than HTML or CSS control.

{% hint style="info" %}
Pick **DOCX** when you want Word-native formatting, editable Word output, and bracket-based S-Docs syntax.

Pick [PDF Templates](/sdocs/template-architecture/document-formats/pdf-templates.md) when you want the layout built directly in the template body.
{% endhint %}

### When DOCX is the right fit

Use DOCX templates when you need:

* Microsoft Word layout and styling tools
* a generated `.docx` file
* merge fields inside a Word document
* conditional sections in Word
* related list tables inside Word tables
* named queries in Microsoft template syntax
* reusable DOCX components

DOCX is a strong fit for contracts, letters, forms, packets, and customer documents that users may keep editing in Word after generation.

### How DOCX templates work

The document design lives in Word.

The dynamic data comes from S-Docs syntax placed inside the Word file.

DOCX templates use bracketed syntax around S-Docs blocks and merge fields.

{% code title="docx-basic-syntax.txt" %}

```plaintext
[{{!Account.Name}}]

[<!--RENDER='{{!Opportunity.StageName}}' == 'Closed Won' -->]
  Approved amount: [{{!Opportunity.Amount #,###.00}}]
[<!--ENDRENDER-->]
```

{% endcode %}

### Build and upload a DOCX template

{% stepper %}
{% step %}

### Create the template record

Create a new S-Docs template.

Set the format to **DOCX**.
{% endstep %}

{% step %}

### Build the document in Microsoft Word

Create the layout in Word just as you want it to appear.

Use normal Word tools for fonts, spacing, tables, headers, and page layout.
{% endstep %}

{% step %}

### Add S-Docs fields and logic

Insert merge fields with DOCX syntax.

Use square brackets around fields, query blocks, and render blocks.
{% endstep %}

{% step %}

### Upload the `.docx` file

Open the template in **Template Editor**.

Upload the Word file so S-Docs can use it for generation.
{% endstep %}

{% step %}

### Generate and test

Test with real record data.

Verify merge fields, table output, images, and conditional sections before rollout.
{% endstep %}
{% endstepper %}

### Core DOCX patterns

#### Merge fields

Wrap merge fields in square brackets.

{% code title="docx-merge-field.txt" %}

```plaintext
[{{!Opportunity.Name}}]
[{{!Contact.Email}}]
```

{% endcode %}

#### Conditional logic

Use bracketed `RENDER` tags.

{% code title="docx-render-block.txt" %}

```plaintext
[<!--RENDER='{{!Opportunity.Amount}}' > '10000' -->]
  Executive approval required.
[<!--ENDRENDER-->]
```

{% endcode %}

#### Component templates

Use a DOCX Component template type here.

{% code title="docx-component.txt" %}

```plaintext
[{{{{!Component Template Name}}}}]
```

{% endcode %}

#### Named queries

Wrap both the query block and the output fields in square brackets.

{% code title="docx-named-query.txt" %}

```plaintext
[{{!<lineitemsSOQL>
  <class>none</class>
  <queryname>TopItem</queryname>
  <soql>
    SELECT Name, TotalPrice
    FROM OpportunityLineItem
    WHERE OpportunityId = '{{!Opportunity.Id}}'
    ORDER BY TotalPrice DESC
    LIMIT 1
  </soql>
</lineitemsSOQL>}}]

[{{!TopItem.Name}}]
[{{!TopItem.TotalPrice #,###.##}}]
```

{% endcode %}

#### Related list tables

DOCX related lists render inside Word tables.

Use a table with:

1. a header row
2. an odd row
3. an even row

Then wrap the table with DOCX table tags.

{% code title="docx-related-list-table.txt" %}

```plaintext
[{{!<lineitemsSOQL>
<tableformat>]

| Product | Quantity | Total |
| sample  | sample   | sample |
| sample  | sample   | sample |

[</tableformat>
<soql>
  SELECT Product2.Name, Quantity, TotalPrice
  FROM OpportunityLineItem
  WHERE OpportunityId = '{{!Opportunity.Id}}'
</soql>
<column>Product2.Name</column>
<column>Quantity</column>
<column format-number="#,###.##" prefix="$">TotalPrice</column>
</lineitemsSOQL>}}]
```

{% endcode %}

### Supported features

DOCX templates support these common S-Docs capabilities:

* merge fields
* conditional logic
* named queries
* related list tables
* component templates
* embedded images
* Word-native formatting and layout

### Important constraints

Keep these DOCX rules in mind:

* Use square brackets around DOCX merge fields and markup blocks.
* Use Word tables for repeating table output.
* Re-upload the file after updating it in Word.
* Live Edit is not supported.

{% hint style="warning" %}
Word spelling and grammar suggestions can break DOCX generation.

Before upload, use the Word Editor to clear all active proofreading marks from the file.
{% endhint %}

### Next reads by goal

* Need merge field syntax? Read [Merge Fields With Microsoft Templates](/sdocs/template-architecture/inserting-merge-fields/merge-fields-with-microsoft-templates-docx-pptx-xlsx.md).
* Need DOCX table setup? Read [How to: Create a Table In Microsoft Templates](/sdocs/advanced-template-logic/related-lists/how-to-create-a-table-in-microsoft-templates-docx-pptx.md).
* Need DOCX conditional syntax? Read [Quick Setup: Conditional Logic With Microsoft Templates](/sdocs/advanced-template-logic/conditional-logic/quick-setup-conditional-logic-with-microsoft-templates-docx-pptx-xlsx.md).
* Need named query patterns? Read [How To: Advanced Data Retrieval with Named Queries](/sdocs/advanced-template-logic/named-query/how-to-advanced-data-retrieval-with-named-queries.md).
* Need DOCX components? Read [Component (DOCX)](/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/component-docx.md).
* Need to fix Word paste styling? Read [Copy from Word: WindowText](broken://spaces/WKNnJmhJBQwhdk5WBFsi/pages/0fbbe8a2be555b1e892a399258485c46d95f454b).
* Need to fix proofreading markup errors? Read [DOCX Generation Failure: SpellStart](/sdocs/template-architecture/document-formats/docx-s-docs/additional-resources/docx-generation-failure-spellstart.md).
* Need checkbox output in DOCX? Read [checkboxes with docx](/sdocs/template-architecture/document-formats/docx-s-docs/additional-resources/checkboxes-with-docx.md).
* Need embedded image troubleshooting? Read [Generating DOCX DOC DOC New Documents with Embedded Images](broken://spaces/WKNnJmhJBQwhdk5WBFsi/pages/7688f493f94359a710ed38a8b84f36d57be00360).


---

# Agent Instructions: 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:

```
GET https://help.sdocs.com/sdocs/template-architecture/document-formats/docx-s-docs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
