Files
docx-js/docs
2022-07-31 15:23:06 +01:00
..
2020-10-13 01:23:27 +01:00
2021-09-23 02:09:09 +01:00
2022-07-08 06:03:49 -07:00
2020-09-05 18:40:40 +01:00
2020-09-05 18:51:50 +01:00
2022-07-31 15:23:06 +01:00
2022-07-06 14:05:37 +01:00

Welcome

Installation

npm install --save docx

Then you can require or import as usual:

const docx = require("docx");
import * as docx from "docx";
// or
import { ... } from "docx";

Basic Usage

import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "docx";

// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
// This simple example will only contain one section
const doc = new Document({
    sections: [
        {
            properties: {},
            children: [
                new Paragraph({
                    children: [
                        new TextRun("Hello World"),
                        new TextRun({
                            text: "Foo Bar",
                            bold: true,
                        }),
                        new TextRun({
                            text: "\tGithub is the best",
                            bold: true,
                        }),
                    ],
                }),
            ],
        },
    ],
});

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("My Document.docx", buffer);
});

// Done! A file called 'My Document.docx' will be in your file system.

clippy the assistant


Made with 💖