Update documentation and README
This commit is contained in:
59
README.md
59
README.md
@ -31,15 +31,15 @@ Press `endpoint` on the `RunKit` website:
|
||||
|
||||

|
||||
|
||||
* 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-demo5 - Images
|
||||
* 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
|
||||
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
||||
* 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-demo5 - Images
|
||||
* 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
|
||||
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
||||
|
||||
#### Run demos locally:
|
||||
|
||||
@ -49,50 +49,17 @@ $ npm run demo
|
||||
|
||||
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.
|
||||
|
||||
## Guide
|
||||
## How to
|
||||
|
||||
Please refer to [the Wiki](https://github.com/dolanmiu/docx/wiki) for details on how to use this library, examples and much more!
|
||||
|
||||
Full documentation can be found here: [http://dolanmiu.github.io/docx/index.html](http://dolanmiu.github.io/docx/index.html)
|
||||
|
||||
## Simple Usage
|
||||
|
||||
```js
|
||||
// Used to create docx files
|
||||
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"));
|
||||
doc.addParagraph(paragraph);
|
||||
|
||||
// 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
|
||||
var exporter = new docx.ExpressPacker(doc, res);
|
||||
|
||||
exporter.pack("My First Document");
|
||||
// If you want to export it as a .pdf file instead
|
||||
exporter.packPdf("My First Document");
|
||||
|
||||
// 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
|
||||
```
|
||||
Please refer to [https://docx.js.org/](https://docx.js.org/) for details on how to use this library, examples and much more!
|
||||
|
||||
## Examples
|
||||
|
||||
Check [the Wiki](https://github.com/dolanmiu/docx/wiki/Examples) and the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples.
|
||||
Check the examples section in the [documentation](https://docx.js.org/#/usage/examples) and the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples.
|
||||
|
||||
# Contributing
|
||||
|
||||
Read the contribution guidelines [here](https://github.com/dolanmiu/docx/wiki/Contributing-Guidelines).
|
||||
Read the contribution guidelines [here](https://docx.js.org/#/contribution-guidelines).
|
||||
|
||||
# Honoured Mentions
|
||||
|
||||
|
@ -3,30 +3,50 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
Easily generate .docx files with JS/TS.
|
||||
Easily generate .docx files with JS/TS. :100:
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
# Welcome
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Installation
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install --save docx
|
||||
npm install --save docx
|
||||
```
|
||||
|
||||
Then you can `require` or `import` as usual:
|
||||
|
||||
```
|
||||
```js
|
||||
let docx = require('docx');
|
||||
```
|
||||
|
||||
```
|
||||
```js
|
||||
import * as docx from 'docx'
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
```js
|
||||
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"));
|
||||
doc.addParagraph(paragraph);
|
||||
|
||||
// Used to export the file into a .docx file
|
||||
var exporter = new docx.LocalPacker(doc);
|
||||
|
||||
exporter.pack("My First Document");
|
||||
|
||||
// Done! A file called 'My First Document.docx' will be in your file system if you used LocalPacker
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
* Include documentation reference(s) at the top of each file:
|
||||
|
||||
```ts
|
||||
```js
|
||||
// http://officeopenxml.com/WPdocument.php
|
||||
```
|
||||
|
||||
@ -18,7 +18,7 @@ Please write a test of every file you make and suffix it with `.spec.ts`.
|
||||
|
||||
Here is a template of a test:
|
||||
|
||||
```ts
|
||||
```js
|
||||
import { assert } from "chai";
|
||||
|
||||
describe("ClassName", () => {
|
||||
|
@ -1,23 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>docx - Generate .docx documents with JavaScript</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="Generate .docx documents with JavaScript">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
|
||||
<meta charset="UTF-8">
|
||||
<title>docx - Generate .docx documents with JavaScript</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="Generate .docx documents with JavaScript">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
name: 'docx',
|
||||
repo: 'https://github.com/dolanmiu/docx',
|
||||
loadSidebar: true,
|
||||
subMaxLevel: 2
|
||||
}
|
||||
</script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
name: 'docx',
|
||||
repo: 'https://github.com/dolanmiu/docx',
|
||||
loadSidebar: true,
|
||||
subMaxLevel: 2,
|
||||
search: 'auto',
|
||||
}
|
||||
</script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></script>
|
||||
<script src="https://unpkg.com/docsify-copy-code@2"></script>
|
||||
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
@ -4,21 +4,21 @@
|
||||
|
||||
Creating Headers and footers is simple. Access the `Header` and `Footer` by doing so like this:
|
||||
|
||||
```ts
|
||||
```js
|
||||
doc.Header;
|
||||
doc.Footer;
|
||||
```
|
||||
|
||||
You can call the same methods as you would with a `File`:
|
||||
|
||||
```ts
|
||||
```js
|
||||
doc.Header.createParagraph("Header text");
|
||||
doc.Footer.createParagraph("Footer text");
|
||||
```
|
||||
|
||||
Even add images:
|
||||
|
||||
```ts
|
||||
```js
|
||||
doc.Header.createImage([PATH_TO_YOUR_IMAGE]);
|
||||
doc.Footer.createImage([PATH_TO_YOUR_IMAGE]);
|
||||
```
|
||||
@ -31,7 +31,7 @@ Also all the supported section properties are implemented according to: http://o
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
```js
|
||||
const header = this.document.createHeader();
|
||||
const footer = this.document.createFooter();
|
||||
|
||||
|
@ -6,7 +6,7 @@ Adding images is very simple
|
||||
|
||||
Simply call the `createImage` method:
|
||||
|
||||
```ts
|
||||
```js
|
||||
const image = doc.createImage([PATH_TO_YOUR_IMAGE]);
|
||||
```
|
||||
|
||||
@ -32,7 +32,7 @@ In Word this is found in:
|
||||
|
||||
The `PictureRun` element support various options to define the positioning of the element in the document.
|
||||
|
||||
```ts
|
||||
```js
|
||||
interface DrawingOptions {
|
||||
position?: PlacementPosition;
|
||||
textWrapping?: TextWrapping;
|
||||
@ -42,7 +42,7 @@ interface DrawingOptions {
|
||||
|
||||
can be passed when creating `PictureRun()` for example:
|
||||
|
||||
```ts
|
||||
```js
|
||||
const imageData = document.createImageData(filename, buffer, 903, 1149);
|
||||
|
||||
new docx.PictureRun(imageData, {
|
||||
@ -68,7 +68,7 @@ When placement position is FLOATING then we can use two options:
|
||||
|
||||
for `drawingOptions.textWrapping` we can define various options. `textWrapping` has the following properties:
|
||||
|
||||
```ts
|
||||
```js
|
||||
interface TextWrapping {
|
||||
textWrapStyle: TextWrapStyle;
|
||||
wrapTextOption?: WrapTextOption;
|
||||
@ -94,7 +94,7 @@ enum WrapTextOption {
|
||||
|
||||
When we want to position the image relative or absolute then we need to use option `drawingOptions.floating`:
|
||||
|
||||
```ts
|
||||
```js
|
||||
export interface Floating {
|
||||
horizontalPosition: HorizontalPositionOptions;
|
||||
verticalPosition: VerticalPositionOptions;
|
||||
|
Reference in New Issue
Block a user