Update documentation and README
This commit is contained in:
@ -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