2018-08-03 23:26:14 +01:00
|
|
|
<p align="center">
|
2018-09-11 19:16:47 +01:00
|
|
|
<img alt="clippy the assistant" src="https://i.imgur.com/pwCV6L8.png">
|
2018-08-03 23:26:14 +01:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<p align="center">
|
2018-08-21 22:29:40 +01:00
|
|
|
Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
|
2018-08-03 23:26:14 +01:00
|
|
|
</p>
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
# Welcome
|
|
|
|
|
2018-08-04 04:03:08 +01:00
|
|
|
## Installation
|
2018-08-04 03:28:27 +01:00
|
|
|
|
|
|
|
```sh
|
2018-08-04 04:03:08 +01:00
|
|
|
npm install --save docx
|
2018-08-04 03:28:27 +01:00
|
|
|
```
|
2018-08-04 04:03:08 +01:00
|
|
|
|
2018-08-04 03:28:27 +01:00
|
|
|
Then you can `require` or `import` as usual:
|
|
|
|
|
2018-08-04 04:03:08 +01:00
|
|
|
```js
|
2018-08-09 03:13:16 +01:00
|
|
|
let docx = require("docx");
|
2018-08-04 03:28:27 +01:00
|
|
|
```
|
|
|
|
|
2018-08-04 04:03:08 +01:00
|
|
|
```js
|
2018-08-09 03:13:16 +01:00
|
|
|
import * as docx from "docx";
|
2018-08-04 03:28:27 +01:00
|
|
|
```
|
|
|
|
|
2018-08-04 04:03:08 +01:00
|
|
|
## Basic Usage
|
|
|
|
|
|
|
|
```js
|
2019-01-02 15:53:28 +00:00
|
|
|
var fs = require("fs");
|
2018-08-04 04:03:08 +01:00
|
|
|
var docx = require("docx");
|
|
|
|
|
|
|
|
// Create 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.addRun(new docx.TextRun("Lorem Ipsum Foo Bar"));
|
2019-06-25 23:17:56 +01:00
|
|
|
doc.add(paragraph);
|
2018-08-04 04:03:08 +01:00
|
|
|
|
|
|
|
// Used to export the file into a .docx file
|
2019-01-02 15:53:28 +00:00
|
|
|
var packer = new docx.Packer();
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My First Document.docx", buffer);
|
|
|
|
});
|
2018-08-04 04:03:08 +01:00
|
|
|
|
2019-01-02 15:53:28 +00:00
|
|
|
// Done! A file called 'My First Document.docx' will be in your file system.
|
2018-08-04 04:03:08 +01:00
|
|
|
```
|
2018-08-04 03:28:27 +01:00
|
|
|
|
2018-08-09 03:13:16 +01:00
|
|
|
## Honoured Mentions
|
|
|
|
|
|
|
|
[@felipeochoa](https://github.com/felipeochoa)
|
|
|
|
|
|
|
|
[@h4buli](https://github.com/h4buli)
|
|
|
|
|
2018-09-11 19:16:47 +01:00
|
|
|
<p align="center">
|
|
|
|
<img alt="clippy the assistant" src="http://i60.tinypic.com/339pvtt.png">
|
|
|
|
</p>
|
|
|
|
|
2018-08-03 23:26:14 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
Made with 💖
|