This commit is contained in:
amitm02
2018-09-04 17:16:31 +03:00
parent 010fde6258
commit 03c4190c2c
20 changed files with 363 additions and 117 deletions

View File

@ -1,26 +1,25 @@
import { Document, Packer, Paragraph, ImportDocx } from "../build";
import * as fs from "fs";
console.log(process.cwd());
let importDocx = new ImportDocx();
fs.readFile("./src/importDocx/simple.dotx", (err, data) => {
const filePath = "./demo/dotx/template.dotx";
fs.readFile(filePath, (err, data) => {
if (err) {
console.log(err);
console.error(`failed to read file ${filePath}.`);
}
else {
importDocx.read(data).then(xmlComp => {
console.log(xmlComp);
const doc = new Document({templateHeader : xmlComp});
// const doc = new Document();
importDocx.extract(data).then(templateDocument => {
let options = {};
options['templateDocument'] = templateDocument;
const doc = new Document(options);
const paragraph = new Paragraph("Hello World");
doc.addParagraph(paragraph);
// console.log(JSON.stringify(xmlComp, null, 2));
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("MyDocument.docx", buffer);
console.log('done. open MyDocument.docx');
});
});

BIN
demo/dotx/simple.dotx Normal file

Binary file not shown.

BIN
demo/dotx/simple2.dotx Normal file

Binary file not shown.

BIN
demo/dotx/template.dotx Normal file

Binary file not shown.

View File

@ -1,13 +0,0 @@
"use strict";
exports.__esModule = true;
var build_1 = require("../build");
var fs = require("fs");
var importDocx = new build_1.ImportDocx();
fs.readFile("./src/import/template.dotx", function (err, data) {
if (err) {
console.log(err);
}
else {
importDocx.read(data);
}
});