2017-03-07 23:10:35 +00:00
< p align = "center" >
< img alt = "clippy the assistant" src = "http://i60.tinypic.com/339pvtt.png" >
< / p >
< p align = "center" >
2017-03-13 01:19:39 +00:00
Generate .docx files with JS/TS very easily, written in TS.
2017-03-07 23:10:35 +00:00
< / p >
2017-03-10 11:27:48 +00:00
2018-02-13 02:08:28 +00:00
---
2017-03-07 23:10:35 +00:00
2018-01-23 01:36:27 +00:00
[![NPM version][npm-image]][npm-url]
2018-05-16 20:10:12 +01:00
[![Downloads per month][downloads-image]][downloads-url]
2018-01-23 01:36:27 +00:00
[![Build Status][travis-image]][travis-url]
2018-05-16 20:00:01 +01:00
[![Dependency Status][daviddm-image]][daviddm-url]
2018-01-23 01:36:27 +00:00
[![Known Vulnerabilities][snky-image]][snky-url]
[![Chat on Gitter][gitter-image]][gitter-url]
[![code style: prettier][prettier-image]][prettier-url]
2018-04-21 00:04:14 +01:00
[![PRs Welcome][pr-image]][pr-url]
2017-03-07 23:12:08 +00:00
2017-03-13 01:21:26 +00:00
# docx
## Install
2016-07-04 09:03:25 +01:00
```sh
$ npm install --save docx
```
2017-03-13 01:21:26 +00:00
## Demo
2018-02-13 02:08:28 +00:00
2018-02-13 02:07:56 +00:00
Press `endpoint` on the `RunKit` website:
2017-03-12 21:37:36 +00:00
2018-04-10 21:42:21 +01:00

2018-02-13 02:10:42 +00:00
* https://runkit.com/dolanmiu/docx-demo1 - Simple paragraph and text
* https://runkit.com/dolanmiu/docx-demo2 - Advanced Paragraphs and text
* https://runkit.com/dolanmiu/docx-demo3 - Bullet points
* https://runkit.com/dolanmiu/docx-demo4 - Simple table
2018-04-10 21:36:11 +01:00
* https://runkit.com/dolanmiu/docx-demo5 - Images
2018-02-13 02:10:42 +00:00
* https://runkit.com/dolanmiu/docx-demo6 - Margins
* https://runkit.com/dolanmiu/docx-demo7 - Landscape
* https://runkit.com/dolanmiu/docx-demo8/1.0.1 - Header and Footer
2018-02-13 23:20:14 +00:00
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
2018-02-13 02:07:56 +00:00
#### Run demos locally:
2018-02-13 02:08:28 +00:00
2017-03-12 21:37:36 +00:00
```sh
$ npm run demo
```
2018-02-13 02:07:56 +00:00
This command will run the demo selector app in the `demo` folder. It will prompt you to select a demo number, which will run a demo from that folder.
2017-03-12 21:37:36 +00:00
2017-03-13 01:21:26 +00:00
## Guide
2017-03-13 00:54:05 +00:00
Please refer to [the Wiki ](https://github.com/dolanmiu/docx/wiki ) for details on how to use this library, examples and much more!
2016-07-04 09:03:25 +01:00
2018-02-21 22:09:42 +00:00
Full documentation can be found here: [http://dolanmiu.github.io/docx/index.html ](http://dolanmiu.github.io/docx/index.html )
2017-04-16 00:09:07 +01:00
2017-03-13 01:21:26 +00:00
## Simple Usage
2016-07-04 09:03:25 +01:00
```js
// Used to create docx files
2018-02-13 02:08:28 +00:00
var docx = require("docx");
2016-07-04 09:03:25 +01:00
2017-03-07 14:42:48 +00:00
// Create document
var doc = new docx.Document();
2016-07-04 09:03:25 +01:00
2017-03-13 01:11:11 +00:00
// Add some content in the document
var paragraph = new docx.Paragraph("Some cool text here.");
// Add more text into the paragraph if you wish
2018-02-13 02:08:28 +00:00
paragraph.addRun(new docx.TextRun("Lorem Ipsum Foo Bar"));
2017-03-13 01:11:11 +00:00
doc.addParagraph(paragraph);
2017-03-07 14:42:48 +00:00
// Used to export the file into a .docx file
2017-03-13 01:11:11 +00:00
var exporter = new docx.LocalPacker(doc);
// Or use the express packer to make the file downloadable.
2017-03-07 14:42:48 +00:00
// res is express' Response object
var exporter = new docx.ExpressPacker(doc, res);
2017-03-13 01:11:11 +00:00
2018-02-13 02:08:28 +00:00
exporter.pack("My First Document");
2017-12-06 01:39:24 +00:00
// If you want to export it as a .pdf file instead
2018-02-13 02:08:28 +00:00
exporter.packPdf("My First Document");
2017-03-13 01:11:11 +00:00
// done! A file called 'My First Document.docx'
// will be in your file system if you used LocalPacker
// Or it will start downloading if you are using Express
2016-07-04 09:03:25 +01:00
```
2017-03-13 01:21:26 +00:00
## Examples
2018-02-13 02:08:28 +00:00
2018-06-27 02:27:56 +01:00
Check [the Wiki ](https://github.com/dolanmiu/docx/wiki/Examples ) and the [demo folder ](https://github.com/dolanmiu/docx/tree/master/demo ) for examples.
2016-07-04 09:03:25 +01:00
2017-09-19 15:56:52 +01:00
# Contributing
Read the contribution guidelines [here ](https://github.com/dolanmiu/docx/wiki/Contributing-Guidelines ).
2018-06-27 02:27:56 +01:00
# Honoured Mentions
[@felipeochoa ](https://github.com/felipeochoa )
[@h4buli ](https://github.com/h4buli )
2018-02-13 02:08:28 +00:00
---
2017-03-10 11:27:48 +00:00
2017-03-11 16:05:20 +00:00
Made with 💖
2017-03-10 11:27:48 +00:00
2016-07-19 19:02:44 +01:00
[npm-image]: https://badge.fury.io/js/docx.svg
[npm-url]: https://npmjs.org/package/docx
2018-05-16 20:10:12 +01:00
[downloads-image]: https://img.shields.io/npm/dm/docx.svg
[downloads-url]: https://npmjs.org/package/docx
2016-07-19 19:02:44 +01:00
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
2016-07-19 18:32:41 +01:00
[travis-url]: https://travis-ci.org/dolanmiu/docx
2016-07-19 19:02:44 +01:00
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
2017-03-08 20:42:56 +00:00
[daviddm-url]: https://david-dm.org/dolanmiu/docx
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
2017-03-10 11:24:41 +00:00
[snky-url]: https://snyk.io/test/github/dolanmiu/docx
2017-03-13 12:30:22 +00:00
[gitter-image]: https://badges.gitter.im/dolanmiu/docx.svg
[gitter-url]: https://gitter.im/docx-lib/Lobby
2018-01-23 01:36:27 +00:00
[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg
[prettier-url]: https://github.com/prettier/prettier
2018-04-21 00:04:14 +01:00
[pr-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
[pr-url]: http://makeapullrequest.com