add simple demo page
This commit is contained in:
15
demo/demo.js
Normal file
15
demo/demo.js
Normal file
@ -0,0 +1,15 @@
|
||||
const docx = require('../build');
|
||||
|
||||
var doc = new docx.Document();
|
||||
|
||||
var paragraph = new docx.Paragraph("Hello World");
|
||||
var institutionText = new docx.TextRun("University College London").bold();
|
||||
var dateText = new docx.TextRun("5th Dec 2015").tab().bold();
|
||||
paragraph.addText(institutionText);
|
||||
paragraph.addText(dateText);
|
||||
|
||||
doc.addParagraph(paragraph);
|
||||
var exporter = new docx.LocalPacker(doc);
|
||||
exporter.pack('My Document');
|
||||
|
||||
console.log('Document created succesfully at project root!');
|
@ -8,7 +8,8 @@
|
||||
"test": "mocha ./build-tests --recursive",
|
||||
"prepublishOnly": "npm run build",
|
||||
"lint": "tslint --project ./ts",
|
||||
"build": "rimraf ./build && tsc -p ts"
|
||||
"build": "rimraf ./build && tsc -p ts",
|
||||
"demo": "npm run build && node ./demo/demo.js"
|
||||
},
|
||||
"files": [
|
||||
"ts",
|
||||
|
@ -18,7 +18,7 @@ export class ExpressPacker extends Packer {
|
||||
}
|
||||
|
||||
public pack(name: string): void {
|
||||
this.res.attachment(name + ".docx");
|
||||
this.res.attachment(`${name}.docx`);
|
||||
super.pack(this.res);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ export class LocalPacker extends Packer {
|
||||
}
|
||||
|
||||
public pack(path: string): void {
|
||||
this.stream = fs.createWriteStream(path);
|
||||
this.stream = fs.createWriteStream(`${path}.docx`);
|
||||
super.pack(this.stream);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user