Skip to content

instantiation

Gabe Webb edited this page Mar 20, 2025 · 1 revision

Starting from nothing

To create a document from nothing is the most straight-forward way to use docxml. This creates a new document entirely devoid of content, styles, relationships, headers/footers, bookmarks and so on.

/** @jsx Docx.jsx */
import Docx, { Paragraph, Text } from 'docxml';

const docx = Docx.fromNothing();

Or, if you already know what should go in your document;

const docx = Docx.fromJsx(<Paragraph>Hello world!</Paragraph>);

The docx instance from the example above provides access to some interesting helper classes that are roughly organised in the way that a DOCX archive is itself;

Starting from a file

For all intents and purposes a .dotx template file is the same as the .docx document instance. You can instantiate docxml from them:

const docx = Docx.fromArchive('my-template.dotx');

The docx instance that returns can be used in all the same ways as if you were to instantiate docxml in another way, but it'll be prepopulated with all the styles, numberings, headers/footers, settings, document contents, etc. that already were in your file.

Clone this wiki locally