Add math run and fraction

This commit is contained in:
Dolan
2019-08-15 00:47:55 +01:00
parent b52a4adaff
commit a1b9be453b
17 changed files with 292 additions and 1 deletions

33
demo/47-math.ts Normal file
View File

@ -0,0 +1,33 @@
// Simple example to add text to a document
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Math, MathDenominator, MathFraction, MathNumerator, MathRun, Packer, Paragraph, TextRun } from "../build";
const doc = new Document();
doc.addSection({
properties: {},
children: [
new Paragraph({
children: [
new Math({
children: [
new MathRun("2+2"),
new MathFraction({
numerator: new MathNumerator("hi"),
denominator: new MathDenominator("2"),
}),
],
}),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});