Skip to main content
Module

x/docx/demo/1-basic.ts

Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
Go to Latest
File
// Simple example to add text to a document// Import from 'docx' rather than '../build' if you install from npmimport * as fs from "fs";import { Document, Packer, Paragraph, TextRun } from "../build";
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, }), ], }), ], }, ],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});