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
|
|
|
|
2017-03-14 10:47:50 +00:00
|
|
|
-----
|
2017-03-07 23:10:35 +00:00
|
|
|
|
2018-01-23 01:36:27 +00:00
|
|
|
[![NPM version][npm-image]][npm-url]
|
|
|
|
[![Build Status][travis-image]][travis-url]
|
|
|
|
[![Dependency Status][gemnasium-image]][gemnasium-url]
|
|
|
|
[![Known Vulnerabilities][snky-image]][snky-url]
|
|
|
|
[![Chat on Gitter][gitter-image]][gitter-url]
|
|
|
|
[![code style: prettier][prettier-image]][prettier-url]
|
2017-03-07 23:12:08 +00:00
|
|
|
|
2016-07-19 19:02:44 +01:00
|
|
|
[](https://nodei.co/npm/docx/)
|
2016-07-04 09:03:25 +01: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:07:56 +00:00
|
|
|
Press `endpoint` on the `RunKit` website:
|
2017-03-12 21:37:36 +00:00
|
|
|
|
2018-02-13 02:07:56 +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
|
|
|
|
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
|
|
|
|
|
|
|
|
#### Run demos locally:
|
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
|
|
|
|
2017-04-16 00:09:07 +01:00
|
|
|
Full documentation can be found here: [http://dolanmiu.github.io/docx](http://dolanmiu.github.io/docx)
|
|
|
|
|
2017-03-13 01:21:26 +00:00
|
|
|
## Simple Usage
|
2016-07-04 09:03:25 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
// Used to create docx files
|
|
|
|
var docx = require('docx');
|
|
|
|
|
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
|
2017-03-14 10:38:05 +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
|
|
|
|
|
|
|
exporter.pack('My First Document');
|
2017-12-06 01:39:24 +00:00
|
|
|
// If you want to export it as a .pdf file instead
|
|
|
|
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
|
2017-03-13 01:19:39 +00:00
|
|
|
Check [the Wiki](https://github.com/dolanmiu/docx/wiki/Examples) 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).
|
|
|
|
|
2017-03-14 10:48:24 +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
|
|
|
|
2017-03-13 01:19:39 +00:00
|
|
|
Huge thanks to [@felipeochoa](https://github.com/felipeochoa) for awesome contributions to this project
|
|
|
|
|
2016-07-19 19:02:44 +01:00
|
|
|
[npm-image]: https://badge.fury.io/js/docx.svg
|
|
|
|
[npm-url]: https://npmjs.org/package/docx
|
|
|
|
[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
|
2017-03-13 16:14:03 +00:00
|
|
|
[gemnasium-image]: https://gemnasium.com/badges/github.com/dolanmiu/docx.svg
|
|
|
|
[gemnasium-url]: https://gemnasium.com/github.com/dolanmiu/docx
|
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
|