Files
docx-js/README.md

110 lines
2.5 KiB
Markdown
Raw Normal View History

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-07 23:13:04 +00:00
Generate .docx files with JS/TS very easily
2017-03-07 23:10:35 +00:00
</p>
2017-03-10 11:27:48 +00:00
=====
2017-03-07 23:10:35 +00:00
2017-03-10 00:52:43 +00:00
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Known Vulnerabilities][snky-image]][snky-url]
2017-03-07 23:12:08 +00:00
2017-03-07 23:10:35 +00:00
# docx
2017-03-07 14:42:48 +00:00
> A tool to create Word Documents (.docx) with JS or TS, written in TS.
2016-07-04 09:03:25 +01:00
2016-07-19 19:02:44 +01:00
[![NPM](https://nodei.co/npm/docx.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/docx/)
2016-07-04 09:03:25 +01:00
# Table of Contents
- [Install](#)
- [Usage](#)
- [Create simple Word Document](#)
- [Exporting](#)
- [Express](#)
- [Standalone .docx file](#)
- [Examples](#)
# Install
```sh
$ npm install --save docx
```
2017-03-12 21:37:36 +00:00
# Demo
```sh
$ npm run demo
```
will run the demo app in the `demo` folder, which creates a file called "My Document.docx" in the root of the project
2017-03-13 00:54:05 +00:00
# Guide
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
# Usage
```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-07 14:42:48 +00:00
// Used to export the file into a .docx file
// res is express' Response object
var exporter = new docx.ExpressPacker(doc, res);
var exporter = new docx.LocalPacker(doc);
2016-07-04 09:03:25 +01:00
```
## Create simple Word Document
```js
var doc = new docx.Document();
2017-03-07 12:51:38 +01:00
var paragraph = new docx.Paragraph();
2016-07-04 09:03:25 +01:00
var text = new docx.TextRun('Hello World');
paragraph.addText(text);
doc.addParagraph(paragraph);
```
### Document properties
You can add properties to the Word document by specifying options, for example:
```js
var doc = new docx.Document({
creator: 'Dolan Miu',
description: 'My extremely interesting document',
title: 'My Document'
});
```
#### Full list of options:
```
creator
description
title
subject
keywords
lastModifiedBy
revision
```
You can mix and match whatever properties you want, or provide no properties.
# Exporting
2017-03-10 11:35:43 +00:00
Check the Wiki for exporting guide
2016-07-04 09:03:25 +01:00
# Examples
2017-03-10 11:24:41 +00:00
Check the Wiki for examples
2016-07-04 09:03:25 +01: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
[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
[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