Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
ed409ac1b7 | |||
4842630e09 | |||
d29286ab6d | |||
ebaf0dfbf0 | |||
72389e25a1 | |||
799bdcc2f0 | |||
9ec7b4969d | |||
e78696fbac | |||
f4102d2e30 | |||
658814d9ca | |||
fd86122881 | |||
ce335c7a3d | |||
bd456d3864 | |||
2414c7c356 | |||
bc6644be0b | |||
46846b6e6c | |||
ac4b5839c2 |
@ -19,7 +19,7 @@
|
||||
[![codecov][codecov-image]][codecov-url]
|
||||
|
||||
<p align="center">
|
||||
<img src="https://i.imgur.com/tBO0XBR.png" alt="drawing"/>
|
||||
<img src="https://i.imgur.com/QeL1HuU.png" alt="drawing"/>
|
||||
</p>
|
||||
|
||||
# Demo
|
||||
@ -29,7 +29,7 @@
|
||||
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
|
||||
|
||||
* https://codepen.io/dolanmiu/pen/RwNeObg
|
||||
* https://jsfiddle.net/dolanmiu/kqxrj35u/1/
|
||||
* https://jsfiddle.net/dolanmiu/onadx1gu/
|
||||
|
||||
Here is an example of `docx` working in `Angular`:
|
||||
|
||||
|
111
demo/64-complex-numbering-text.ts
Normal file
111
demo/64-complex-numbering-text.ts
Normal file
@ -0,0 +1,111 @@
|
||||
// Numbered lists - With complex number text
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, LevelFormat } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
config: [
|
||||
{
|
||||
reference: "ref1",
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%1",
|
||||
},
|
||||
{
|
||||
level: 1,
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%1.%2",
|
||||
},
|
||||
{
|
||||
level: 2,
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%1.%2.%3",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
sections: [
|
||||
{
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "REF1 - lvl:0",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - lvl:1",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
level: 1,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - lvl:2",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
level: 2,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - lvl:0",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - lvl:0",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - lvl:0",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Random text",
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - inst:1 - lvl:0",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
instance: 1,
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - inst:0 - lvl:0",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
instance: 0,
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "REF1 - inst:0 - lvl:0",
|
||||
numbering: {
|
||||
reference: "ref1",
|
||||
instance: 0,
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Used to export the file into a .docx file
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("6-numbering.docx", buffer);
|
||||
});
|
BIN
logo/readme-demo.psd
Normal file
BIN
logo/readme-demo.psd
Normal file
Binary file not shown.
34
package-lock.json
generated
34
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "5.5.0",
|
||||
"version": "6.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -560,9 +560,9 @@
|
||||
}
|
||||
},
|
||||
"@types/mocha": {
|
||||
"version": "8.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.1.tgz",
|
||||
"integrity": "sha512-NysN+bNqj6E0Hv4CTGWSlPzMW6vTKjDpOteycDkV4IWBsO+PU48JonrPzV9ODjiI2XrjmA05KInLgF5ivZ/YGQ==",
|
||||
"version": "8.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.2.tgz",
|
||||
"integrity": "sha512-Lwh0lzzqT5Pqh6z61P3c3P5nm6fzQK/MMHl9UKeneAeInVflBSz1O2EkX6gM6xfJd7FBXBY5purtLx7fUiZ7Hw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
@ -5640,9 +5640,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"nise": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/nise/-/nise-4.0.4.tgz",
|
||||
"integrity": "sha512-bTTRUNlemx6deJa+ZyoCUTRvH3liK5+N6VQZ4NIw90AgDXY6iPnsqplNFf6STcj+ePk0H/xqxnP75Lr0J0Fq3A==",
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/nise/-/nise-4.1.0.tgz",
|
||||
"integrity": "sha512-eQMEmGN/8arp0xsvGoQ+B1qvSkR73B1nWSCh7nOt5neMCtwcQVYQGdzQMhcNscktTsWB54xnlSQFzOAPJD8nXA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@sinonjs/commons": "^1.7.0",
|
||||
@ -7361,16 +7361,16 @@
|
||||
"dev": true
|
||||
},
|
||||
"sinon": {
|
||||
"version": "9.2.4",
|
||||
"resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz",
|
||||
"integrity": "sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==",
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/sinon/-/sinon-10.0.0.tgz",
|
||||
"integrity": "sha512-XAn5DxtGVJBlBWYrcYKEhWCz7FLwZGdyvANRyK06419hyEpdT0dMc5A8Vcxg5SCGHc40CsqoKsc1bt1CbJPfNw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@sinonjs/commons": "^1.8.1",
|
||||
"@sinonjs/fake-timers": "^6.0.1",
|
||||
"@sinonjs/samsam": "^5.3.1",
|
||||
"diff": "^4.0.2",
|
||||
"nise": "^4.0.4",
|
||||
"nise": "^4.1.0",
|
||||
"supports-color": "^7.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -8106,9 +8106,9 @@
|
||||
}
|
||||
},
|
||||
"typedoc": {
|
||||
"version": "0.20.32",
|
||||
"resolved": "http://registry.npmjs.org/typedoc/-/typedoc-0.20.32.tgz",
|
||||
"integrity": "sha512-GSopd/tiqoKE3fEdvhoaEpR9yrEPsR9tknAjkoeSPL6p1Rq5aVsKxBhhF6cwoDJ7oWjpvnm8vs0rQN0BxEHuWQ==",
|
||||
"version": "0.20.33",
|
||||
"resolved": "http://registry.npmjs.org/typedoc/-/typedoc-0.20.33.tgz",
|
||||
"integrity": "sha512-jzNdHmjZRQKwguhpXjIPuIjz+TpdgG2AVY8ta+qpAukv+3rBhTs4AAVd+mkonrHVYlC0EAbuAJ4urkfnn42Hwg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"colors": "^1.4.0",
|
||||
@ -8173,9 +8173,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.13.1",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.1.tgz",
|
||||
"integrity": "sha512-EWhx3fHy3M9JbaeTnO+rEqzCe1wtyQClv6q3YWq0voOj4E+bMZBErVS1GAHPDiRGONYq34M1/d8KuQMgvi6Gjw==",
|
||||
"version": "3.13.2",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.2.tgz",
|
||||
"integrity": "sha512-SbMu4D2Vo95LMC/MetNaso1194M1htEA+JrqE9Hk+G2DhI+itfS9TRu9ZKeCahLDNa/J3n4MqUJ/fOHMzQpRWw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "6.0.0",
|
||||
"version": "6.0.2",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
@ -85,7 +85,7 @@
|
||||
"request-promise": "^4.2.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"shelljs": "^0.8.4",
|
||||
"sinon": "^9.0.2",
|
||||
"sinon": "^10.0.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-immutable": "^6.0.1",
|
||||
|
@ -20,7 +20,7 @@ describe("Utility", () => {
|
||||
describe("#uniqueNumericId", () => {
|
||||
it("should generate a unique ID", () => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(uniqueNumericId()).to.not.be.empty;
|
||||
expect(uniqueNumericId()).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { customAlphabet, nanoid } from "nanoid/non-secure";
|
||||
import { nanoid } from "nanoid/non-secure";
|
||||
|
||||
const numericNanoId = customAlphabet("0123456789", 15);
|
||||
let currentCount = 0;
|
||||
|
||||
// Twip - twentieths of a point
|
||||
export const convertMillimetersToTwip = (millimeters: number): number => {
|
||||
@ -12,7 +12,7 @@ export const convertInchesToTwip = (inches: number): number => {
|
||||
};
|
||||
|
||||
export const uniqueNumericId = (): number => {
|
||||
return parseFloat(numericNanoId());
|
||||
return currentCount++;
|
||||
};
|
||||
|
||||
export const uniqueId = (): string => {
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { uniqueId } from "convenience-functions";
|
||||
|
||||
import { IContext, IXmlableObject } from "file/xml-components";
|
||||
|
||||
import { Drawing, IFloating } from "../../drawing";
|
||||
import { IMediaTransformation } from "../../media";
|
||||
import { IMediaData } from "../../media/data";
|
||||
import { Run } from "../run";
|
||||
import { IContext, IXmlableObject } from "/file/xml-components";
|
||||
|
||||
export interface IImageOptions {
|
||||
readonly data: Buffer | string | Uint8Array | ArrayBuffer;
|
||||
|
@ -31,6 +31,10 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
||||
constructor(options: ITablePropertiesOptions) {
|
||||
super("w:tblPr");
|
||||
|
||||
if (options.style) {
|
||||
this.root.push(new TableStyle(options.style));
|
||||
}
|
||||
|
||||
this.root.push(new TableCellMargin(options.cellMargin || {}));
|
||||
|
||||
if (options.borders) {
|
||||
@ -60,9 +64,5 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
||||
if (options.visuallyRightToLeft) {
|
||||
this.root.push(new VisuallyRightToLeft());
|
||||
}
|
||||
|
||||
if (options.style) {
|
||||
this.root.push(new TableStyle(options.style));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user