works!
This commit is contained in:
@ -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
BIN
demo/dotx/simple.dotx
Normal file
Binary file not shown.
BIN
demo/dotx/simple2.dotx
Normal file
BIN
demo/dotx/simple2.dotx
Normal file
Binary file not shown.
BIN
demo/dotx/template.dotx
Normal file
BIN
demo/dotx/template.dotx
Normal file
Binary file not shown.
@ -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);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user