Files
docx-js/demo/demo27.ts

27 lines
877 B
TypeScript
Raw Normal View History

2018-08-29 18:36:48 +03:00
import { Document, Packer, Paragraph, ImportDocx } from "../build";
import * as fs from "fs";
let importDocx = new ImportDocx();
2018-09-04 17:16:31 +03:00
const filePath = "./demo/dotx/template.dotx";
fs.readFile(filePath, (err, data) => {
2018-08-29 18:36:48 +03:00
if (err) {
2018-09-04 17:16:31 +03:00
console.error(`failed to read file ${filePath}.`);
2018-08-29 18:36:48 +03:00
}
else {
2018-09-04 17:16:31 +03:00
importDocx.extract(data).then(templateDocument => {
let options = {};
options['templateDocument'] = templateDocument;
const doc = new Document(options);
2018-08-29 18:36:48 +03:00
const paragraph = new Paragraph("Hello World");
doc.addParagraph(paragraph);
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("MyDocument.docx", buffer);
2018-09-04 17:16:31 +03:00
console.log('done. open MyDocument.docx');
2018-08-29 18:36:48 +03:00
});
});
}
});