Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

DOCX Demo 3

node v10.24.1
version: 4.0.0
endpointsharetweet
const docx = require('docx@4.0.0'); const express = require("@runkit/runkit/express-endpoint/1.0.0"); const app = express(exports); const { Document, Indent, Numbering, Paragraph, Packer } = docx; app.get("/", async (req, res) => { const doc = new Document(); const numbering = new Numbering(); const abstractNum = numbering.createAbstractNumbering(); abstractNum.createLevel(0, "upperRoman", "%1", "start") .addParagraphProperty(new Indent(720, 260)); abstractNum.createLevel(1, "decimal", "%2.", "start") .addParagraphProperty(new Indent(1440, 980)); abstractNum.createLevel(2, "lowerLetter", "%3)", "start") .addParagraphProperty(new Indent(2160, 1700)); const concrete = numbering.createConcreteNumbering(abstractNum); const topLevelP = new Paragraph("Hey you"); const subP = new Paragraph("What's up fam"); const secondSubP = new Paragraph("Hello World 2"); const subSubP = new Paragraph("Yeah boi"); topLevelP.setNumbering(concrete, 0); subP.setNumbering(concrete, 1); secondSubP.setNumbering(concrete, 1); subSubP.setNumbering(concrete, 2); doc.addParagraph(topLevelP); doc.addParagraph(subP); doc.addParagraph(secondSubP); doc.addParagraph(subSubP); const packer = new Packer(); const b64string = await packer.toBase64String(doc); res.setHeader('Content-Disposition', 'attachment; filename=My Document.docx'); res.send(Buffer.from(b64string, 'base64')); });
Loading…

1 comment

  • posted 2 years ago by 114632289
    very goods

sign in to comment