made usage much more clear

This commit is contained in:
Dolan
2017-03-13 01:11:11 +00:00
committed by GitHub
parent 2662bcc60b
commit bf2e5201c8

View File

@ -42,7 +42,7 @@ will run the demo app in the `demo` folder, which creates a file called "My Docu
Please refer to [the Wiki](https://github.com/dolanmiu/docx/wiki) for details on how to use this library, examples and much more! Please refer to [the Wiki](https://github.com/dolanmiu/docx/wiki) for details on how to use this library, examples and much more!
# Usage # Simple Usage
```js ```js
// Used to create docx files // Used to create docx files
@ -51,19 +51,24 @@ var docx = require('docx');
// Create document // Create document
var doc = new docx.Document(); var doc = new docx.Document();
// Add some content in the document
var paragraph = new docx.Paragraph("Some cool text here.");
// Add more text into the paragraph if you wish
paragraph.addText(new docx.TextRun('Lorem Ipsum Foo Bar'));
doc.addParagraph(paragraph);
// Used to export the file into a .docx file // Used to export the file into a .docx file
var exporter = new docx.LocalPacker(doc);
// Or use the express packer to make the file downloadable.
// res is express' Response object // res is express' Response object
var exporter = new docx.ExpressPacker(doc, res); var exporter = new docx.ExpressPacker(doc, res);
var exporter = new docx.LocalPacker(doc);
``` exporter.pack('My First Document');
## Create simple Word Document
```js // done! A file called 'My First Document.docx'
var doc = new docx.Document(); // will be in your file system if you used LocalPacker
// Or it will start downloading if you are using Express
var paragraph = new docx.Paragraph();
var text = new docx.TextRun('Hello World');
paragraph.addText(text);
doc.addParagraph(paragraph);
``` ```
### Document properties ### Document properties