Compare commits
86 Commits
Author | SHA1 | Date | |
---|---|---|---|
3006f4d2c1 | |||
7f88a38219 | |||
a481518470 | |||
2435ebf16e | |||
62d0767ceb | |||
8024c01a82 | |||
1b380c3fdb | |||
06b67bd292 | |||
8a1087f601 | |||
ff09d6515c | |||
ebe85d8e14 | |||
5dc27ac46a | |||
1dcc8ee761 | |||
f789f60e22 | |||
32e3f07d57 | |||
9ea41ab3ce | |||
4b8d062862 | |||
d9408029f3 | |||
9fe0406078 | |||
3ea453a07f | |||
984e762a53 | |||
1592aa7117 | |||
62b4522c94 | |||
8b86751c95 | |||
afa380e336 | |||
feebff9077 | |||
028b50ff99 | |||
559e81c3fe | |||
4da6b98437 | |||
5b2409c76f | |||
ff027d172e | |||
3f23290a46 | |||
f1a10d32e6 | |||
a71f40e873 | |||
7f449319cd | |||
ab5c8ea698 | |||
68cfa9360b | |||
f627e3d994 | |||
7c870548d9 | |||
57ccc41547 | |||
988ba45197 | |||
df6606041b | |||
3ae27b466f | |||
69f5e21435 | |||
6da73c612a | |||
e1b1c1492f | |||
6ca13c4fce | |||
b474567d20 | |||
c07170902e | |||
0f201d2f4b | |||
b875d6f183 | |||
831b92239d | |||
66b91c22dd | |||
1242c0689f | |||
4386d02526 | |||
3ba521f8cc | |||
85bb818ae6 | |||
be7e2aa8fe | |||
7f71f6e3f1 | |||
a94d23e2ae | |||
133c255ce2 | |||
863e27ff9b | |||
5c63e6ae12 | |||
10dd36569d | |||
be5985fb6a | |||
0d7f169613 | |||
eaddcb83ab | |||
9a6885f124 | |||
7284ee818b | |||
20964454c4 | |||
d7670929d1 | |||
58f0761423 | |||
3f28bc09bc | |||
6efa734e81 | |||
47d64af737 | |||
4a2b91ce07 | |||
080a77cc73 | |||
9b874b0061 | |||
ff8a2ed538 | |||
251eafe103 | |||
64b604c9ac | |||
72fc5f9874 | |||
71dcdf0ca2 | |||
e23fc987a7 | |||
36dba1a36f | |||
1b1547d4b6 |
@ -29,11 +29,12 @@ Here are examples of `docx` being used with basic `HTML/JS` in a browser environ
|
|||||||
- https://codepen.io/dolanmiu/pen/RwNeObg
|
- https://codepen.io/dolanmiu/pen/RwNeObg
|
||||||
- https://jsfiddle.net/dolanmiu/onadx1gu/
|
- https://jsfiddle.net/dolanmiu/onadx1gu/
|
||||||
|
|
||||||
Here is an example of `docx` working in `Angular`:
|
Here are examples of `docx` working in `Angular`:
|
||||||
|
|
||||||
- https://stackblitz.com/edit/angular-docx
|
- https://stackblitz.com/edit/angular-docx
|
||||||
|
- https://stackblitz.com/edit/angular-wmd6k3
|
||||||
|
|
||||||
Here is an example of `docx` working in `React`:
|
Here are examples of `docx` working in `React`:
|
||||||
|
|
||||||
- https://stackblitz.com/edit/react-docx
|
- https://stackblitz.com/edit/react-docx
|
||||||
- https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
- https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
||||||
|
@ -14,6 +14,7 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "Foo Bar",
|
text: "Foo Bar",
|
||||||
bold: true,
|
bold: true,
|
||||||
|
size: 40,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
children: [new Tab(), "Github is the best"],
|
children: [new Tab(), "Github is the best"],
|
||||||
|
@ -222,6 +222,15 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "Underline and Strike",
|
text: "Underline and Strike",
|
||||||
}),
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " Override Underline ",
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.NONE,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "Strike and Underline",
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
|
27
demo/78-thai-distributed.ts
Normal file
27
demo/78-thai-distributed.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "บริษัท บิสกิด จำกัด (บริษัทฯ) ได้จดทะเบียนจัดตั้งขึ้นเป็นบริษัทจำกัดตามประมวลกฎหมายแพ่งและพาณิชย์ของประเทศไทย เมื่อวันที่ 30 พฤษภาคม 2561 ทะเบียนนิติบุคคลเลขที่ 0845561005665",
|
||||||
|
size: 36,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
193
demo/79-table-from-data-source.ts
Normal file
193
demo/79-table-from-data-source.ts
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
// Example of how you would create a table and add data to it from a data source
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
VerticalAlign,
|
||||||
|
TextDirection,
|
||||||
|
TextRun,
|
||||||
|
WidthType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
interface StockPrice {
|
||||||
|
readonly date: Date;
|
||||||
|
readonly ticker: string;
|
||||||
|
readonly price: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DATA: StockPrice[] = [
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-28"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 18.12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-29"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.15,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-30"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.46,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-31"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.78,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-04"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 20.59,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-05"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.54,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-06"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.29,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-07"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 18.82,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-10"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.53,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-11"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.36,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-12"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.55,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-13"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-14"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.83,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-17"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.77,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const generateRows = (prices: StockPrice[]): TableRow[] =>
|
||||||
|
prices.map(
|
||||||
|
({ date, ticker, price }) =>
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(date.toString())],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(ticker)],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(price.toString())],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Table({
|
||||||
|
width: {
|
||||||
|
size: 9070,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Date",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Ticker",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Price",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
...generateRows(DATA),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
49
demo/79-thai-distributed.ts
Normal file
49
demo/79-thai-distributed.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, convertMillimetersToTwip, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "test",
|
||||||
|
name: "Test",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertMillimetersToTwip(6.4) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
margin: {
|
||||||
|
top: 0,
|
||||||
|
right: convertMillimetersToTwip(24),
|
||||||
|
bottom: convertMillimetersToTwip(24),
|
||||||
|
left: convertMillimetersToTwip(24),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "บริษัทฯ มีเงินสด 41,985.00 บาท และ 25,855.66 บาทตามลำดับ เงินสดทั้งจำนวนอยู่ในความดูแลและรับผิดชอบของกรรมการ บริษัทฯบันทึกการรับชำระเงินและการจ่ายชำระเงินผ่านบัญชีเงินสดเพียงเท่านั้น ซึ่งอาจกระทบต่อความถูกต้องครบถ้วนของการบันทึกบัญชี ทั้งนี้ขึ้นอยู่กับระบบการควบคุมภายในของบริษัท",
|
||||||
|
size: 28,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -11,8 +11,10 @@
|
|||||||
- [Document](usage/document.md)
|
- [Document](usage/document.md)
|
||||||
- [Sections](usage/sections.md)
|
- [Sections](usage/sections.md)
|
||||||
- [Paragraph](usage/paragraph.md)
|
- [Paragraph](usage/paragraph.md)
|
||||||
|
- [Text Frames](usage/text-frames.md)
|
||||||
|
- [Symbols](usage/symbols.md)
|
||||||
- [Text](usage/text.md)
|
- [Text](usage/text.md)
|
||||||
- [Image](usage/images.md)
|
- [Images](usage/images.md)
|
||||||
- [Headers & Footers](usage/headers-and-footers.md)
|
- [Headers & Footers](usage/headers-and-footers.md)
|
||||||
- [Bullet Points](usage/bullet-points.md)
|
- [Bullet Points](usage/bullet-points.md)
|
||||||
- [Hyperlinks](usage/hyperlinks.md)
|
- [Hyperlinks](usage/hyperlinks.md)
|
||||||
@ -23,10 +25,12 @@
|
|||||||
- [Page Numbers](usage/page-numbers.md)
|
- [Page Numbers](usage/page-numbers.md)
|
||||||
- [Change Tracking](usage/change-tracking.md)
|
- [Change Tracking](usage/change-tracking.md)
|
||||||
- [Math](usage/math.md)
|
- [Math](usage/math.md)
|
||||||
- [Text Frames](usage/text-frames.md)
|
- [Comments](usage/comments.md)
|
||||||
|
- [Footnotes](usage/footnotes.md)
|
||||||
|
- [Fields](usage/fields.md)
|
||||||
- Styling
|
- Styling
|
||||||
_ [Styling with JS](usage/styling-with-js.md)
|
- [Styling with JS](usage/styling-with-js.md)
|
||||||
_ [Styling with XML](usage/styling-with-xml.md)
|
- [Styling with XML](usage/styling-with-xml.md)
|
||||||
|
|
||||||
- Exporting
|
- Exporting
|
||||||
|
|
||||||
|
@ -61,13 +61,13 @@ const doc = new Document({
|
|||||||
This is the list of options for a paragraph. A detailed explanation is below:
|
This is the list of options for a paragraph. A detailed explanation is below:
|
||||||
|
|
||||||
| Property | Type | Mandatory? | Possible Values |
|
| Property | Type | Mandatory? | Possible Values |
|
||||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------- |
|
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [text](#text) | `string` | Optional | |
|
| [text](#text) | `string` | Optional | |
|
||||||
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
||||||
| [border](#border) | `IBorderOptions` | Optional | `top`, `bottom`, `left`, `right`. Each of these are of type IBorderPropertyOptions. Click here for Example |
|
| [border](#border) | `IBorderOptions` | Optional | `top`, `bottom`, `left`, `right`. Each of these are of type IBorderPropertyOptions. Click here for Example |
|
||||||
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
||||||
| [outlineLevel](#outline-level) | `number` | Optional | |
|
| [outlineLevel](#outline-level) | `number` | Optional | |
|
||||||
| alignment | `AlignmentType` | Optional | |
|
| alignment | `AlignmentType` | Optional | `START`, `CENTER`, `END`, `BOTH`, `MEDIUM_KASHIDA`, `DISTRIBUTE`, `NUM_TAB`, `HIGH_KASHIDA`, `LOW_KASHIDA`, `THAI_DISTRIBUTE`, `LEFT`, `RIGHT`, `JUSTIFIED` |
|
||||||
| heading | `HeadingLevel` | Optional | |
|
| heading | `HeadingLevel` | Optional | |
|
||||||
| bidirectional | `boolean` | Optional | |
|
| bidirectional | `boolean` | Optional | |
|
||||||
| thematicBreak | `boolean` | Optional | |
|
| thematicBreak | `boolean` | Optional | |
|
||||||
@ -181,11 +181,13 @@ Adding spacing between paragraphs
|
|||||||
### ISpacingProperties
|
### ISpacingProperties
|
||||||
|
|
||||||
| Property | Type | Notes | Possible Values |
|
| Property | Type | Notes | Possible Values |
|
||||||
| -------- | -------------- | -------- | ----------------------------- |
|
| -------- | -------------- | -------- | -------------------------------------- |
|
||||||
| after | `number` | Optional | |
|
| after | `number` | Optional | |
|
||||||
| before | `number` | Optional | |
|
| before | `number` | Optional | |
|
||||||
| line | `number` | Optional | |
|
| line | `number` | Optional | |
|
||||||
| lineRule | `LineRuleType` | Optional | `AT_LEAST`, `EXACTLY`, `AUTO` |
|
| lineRule | `LineRuleType` | Optional | `AT_LEAST`, `EXACTLY`, `EXACT`, `AUTO` |
|
||||||
|
|
||||||
|
Note: The `lineRule` property has different values depending on the version of Word you are using. The `EXACTLY` value is only available in Word 2016 and above. Use `EXACT` for greater support, including LibreOffice etc. Read this issue for more information: https://github.com/dolanmiu/docx/issues/1773.
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
|
1175
package-lock.json
generated
1175
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "7.7.0",
|
"version": "7.8.2",
|
||||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -84,7 +84,7 @@
|
|||||||
"eslint-plugin-jsdoc": "^39.3.6",
|
"eslint-plugin-jsdoc": "^39.3.6",
|
||||||
"eslint-plugin-no-null": "^1.0.2",
|
"eslint-plugin-no-null": "^1.0.2",
|
||||||
"eslint-plugin-prefer-arrow": "^1.2.3",
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||||
"eslint-plugin-unicorn": "^44.0.0",
|
"eslint-plugin-unicorn": "^45.0.0",
|
||||||
"glob": "^8.0.1",
|
"glob": "^8.0.1",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
"mocha": "^10.0.0",
|
"mocha": "^10.0.0",
|
||||||
@ -98,17 +98,17 @@
|
|||||||
"request-promise": "^4.2.2",
|
"request-promise": "^4.2.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"shelljs": "^0.8.4",
|
"shelljs": "^0.8.4",
|
||||||
"sinon": "^14.0.0",
|
"sinon": "^15.0.0",
|
||||||
"stream-browserify": "^3.0.0",
|
"stream-browserify": "^3.0.0",
|
||||||
"ts-loader": "^9.0.0",
|
"ts-loader": "^9.0.0",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"tsconfig-paths": "^4.0.0",
|
"tsconfig-paths": "^4.0.0",
|
||||||
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
||||||
"typedoc": "^0.23.2",
|
"typedoc": "^0.23.2",
|
||||||
"typescript": "4.8.4",
|
"typescript": "4.9.4",
|
||||||
"unzipper": "^0.10.11",
|
"unzipper": "^0.10.11",
|
||||||
"webpack": "^5.28.0",
|
"webpack": "^5.28.0",
|
||||||
"webpack-cli": "^4.6.0"
|
"webpack-cli": "^5.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
@ -75,7 +75,7 @@ export class PageBorders extends IgnoreIfEmptyXmlComponent {
|
|||||||
super("w:pgBorders");
|
super("w:pgBorders");
|
||||||
|
|
||||||
if (!options) {
|
if (!options) {
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.pageBorders) {
|
if (options.pageBorders) {
|
||||||
|
@ -8,7 +8,7 @@ import { DocumentAttributes } from "./document-attributes";
|
|||||||
import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background";
|
import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background";
|
||||||
|
|
||||||
export interface IDocumentOptions {
|
export interface IDocumentOptions {
|
||||||
readonly background: IDocumentBackgroundOptions;
|
readonly background?: IDocumentBackgroundOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:element name="document" type="CT_Document"/>
|
// <xsd:element name="document" type="CT_Document"/>
|
||||||
@ -73,7 +73,9 @@ export class Document extends XmlComponent {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
this.body = new Body();
|
this.body = new Body();
|
||||||
|
if (options.background) {
|
||||||
this.root.push(new DocumentBackground(options.background));
|
this.root.push(new DocumentBackground(options.background));
|
||||||
|
}
|
||||||
this.root.push(this.body);
|
this.root.push(this.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ export class File {
|
|||||||
this.appProperties = new AppProperties();
|
this.appProperties = new AppProperties();
|
||||||
this.footnotesWrapper = new FootnotesWrapper();
|
this.footnotesWrapper = new FootnotesWrapper();
|
||||||
this.contentTypes = new ContentTypes();
|
this.contentTypes = new ContentTypes();
|
||||||
this.documentWrapper = new DocumentWrapper({ background: options.background || {} });
|
this.documentWrapper = new DocumentWrapper({ background: options.background });
|
||||||
this.settings = new Settings({
|
this.settings = new Settings({
|
||||||
compatibilityModeVersion: options.compatabilityModeVersion,
|
compatibilityModeVersion: options.compatabilityModeVersion,
|
||||||
compatibility: options.compatibility,
|
compatibility: options.compatibility,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// http://officeopenxml.com/WPnumbering-numFmt.php
|
// http://officeopenxml.com/WPnumbering-numFmt.php
|
||||||
|
// http://www.datypic.com/sc/ooxml/a-w_val-57.html
|
||||||
import { Attributes, NumberValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { Attributes, NumberValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { decimalNumber } from "@util/values";
|
import { decimalNumber } from "@util/values";
|
||||||
|
|
||||||
@ -6,21 +7,138 @@ import { AlignmentType } from "../paragraph/formatting";
|
|||||||
import { ILevelParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
import { ILevelParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
||||||
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
||||||
|
|
||||||
|
// TODO: Breaking change - consolidate with number-format
|
||||||
|
// <xsd:simpleType name="ST_NumberFormat">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="decimal"/>
|
||||||
|
// <xsd:enumeration value="upperRoman"/>
|
||||||
|
// <xsd:enumeration value="lowerRoman"/>
|
||||||
|
// <xsd:enumeration value="upperLetter"/>
|
||||||
|
// <xsd:enumeration value="lowerLetter"/>
|
||||||
|
// <xsd:enumeration value="ordinal"/>
|
||||||
|
// <xsd:enumeration value="cardinalText"/>
|
||||||
|
// <xsd:enumeration value="ordinalText"/>
|
||||||
|
// <xsd:enumeration value="hex"/>
|
||||||
|
// <xsd:enumeration value="chicago"/>
|
||||||
|
// <xsd:enumeration value="ideographDigital"/>
|
||||||
|
// <xsd:enumeration value="japaneseCounting"/>
|
||||||
|
// <xsd:enumeration value="aiueo"/>
|
||||||
|
// <xsd:enumeration value="iroha"/>
|
||||||
|
// <xsd:enumeration value="decimalFullWidth"/>
|
||||||
|
// <xsd:enumeration value="decimalHalfWidth"/>
|
||||||
|
// <xsd:enumeration value="japaneseLegal"/>
|
||||||
|
// <xsd:enumeration value="japaneseDigitalTenThousand"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedCircle"/>
|
||||||
|
// <xsd:enumeration value="decimalFullWidth2"/>
|
||||||
|
// <xsd:enumeration value="aiueoFullWidth"/>
|
||||||
|
// <xsd:enumeration value="irohaFullWidth"/>
|
||||||
|
// <xsd:enumeration value="decimalZero"/>
|
||||||
|
// <xsd:enumeration value="bullet"/>
|
||||||
|
// <xsd:enumeration value="ganada"/>
|
||||||
|
// <xsd:enumeration value="chosung"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedFullstop"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedParen"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedCircleChinese"/>
|
||||||
|
// <xsd:enumeration value="ideographEnclosedCircle"/>
|
||||||
|
// <xsd:enumeration value="ideographTraditional"/>
|
||||||
|
// <xsd:enumeration value="ideographZodiac"/>
|
||||||
|
// <xsd:enumeration value="ideographZodiacTraditional"/>
|
||||||
|
// <xsd:enumeration value="taiwaneseCounting"/>
|
||||||
|
// <xsd:enumeration value="ideographLegalTraditional"/>
|
||||||
|
// <xsd:enumeration value="taiwaneseCountingThousand"/>
|
||||||
|
// <xsd:enumeration value="taiwaneseDigital"/>
|
||||||
|
// <xsd:enumeration value="chineseCounting"/>
|
||||||
|
// <xsd:enumeration value="chineseLegalSimplified"/>
|
||||||
|
// <xsd:enumeration value="chineseCountingThousand"/>
|
||||||
|
// <xsd:enumeration value="koreanDigital"/>
|
||||||
|
// <xsd:enumeration value="koreanCounting"/>
|
||||||
|
// <xsd:enumeration value="koreanLegal"/>
|
||||||
|
// <xsd:enumeration value="koreanDigital2"/>
|
||||||
|
// <xsd:enumeration value="vietnameseCounting"/>
|
||||||
|
// <xsd:enumeration value="russianLower"/>
|
||||||
|
// <xsd:enumeration value="russianUpper"/>
|
||||||
|
// <xsd:enumeration value="none"/>
|
||||||
|
// <xsd:enumeration value="numberInDash"/>
|
||||||
|
// <xsd:enumeration value="hebrew1"/>
|
||||||
|
// <xsd:enumeration value="hebrew2"/>
|
||||||
|
// <xsd:enumeration value="arabicAlpha"/>
|
||||||
|
// <xsd:enumeration value="arabicAbjad"/>
|
||||||
|
// <xsd:enumeration value="hindiVowels"/>
|
||||||
|
// <xsd:enumeration value="hindiConsonants"/>
|
||||||
|
// <xsd:enumeration value="hindiNumbers"/>
|
||||||
|
// <xsd:enumeration value="hindiCounting"/>
|
||||||
|
// <xsd:enumeration value="thaiLetters"/>
|
||||||
|
// <xsd:enumeration value="thaiNumbers"/>
|
||||||
|
// <xsd:enumeration value="thaiCounting"/>
|
||||||
|
// <xsd:enumeration value="bahtText"/>
|
||||||
|
// <xsd:enumeration value="dollarText"/>
|
||||||
|
// <xsd:enumeration value="custom"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
export enum LevelFormat {
|
export enum LevelFormat {
|
||||||
BULLET = "bullet",
|
|
||||||
CARDINAL_TEXT = "cardinalText",
|
|
||||||
CHICAGO = "chicago",
|
|
||||||
DECIMAL = "decimal",
|
DECIMAL = "decimal",
|
||||||
|
UPPER_ROMAN = "upperRoman",
|
||||||
|
LOWER_ROMAN = "lowerRoman",
|
||||||
|
UPPER_LETTER = "upperLetter",
|
||||||
|
LOWER_LETTER = "lowerLetter",
|
||||||
|
ORDINAL = "ordinal",
|
||||||
|
CARDINAL_TEXT = "cardinalText",
|
||||||
|
ORDINAL_TEXT = "ordinalText",
|
||||||
|
HEX = "hex",
|
||||||
|
CHICAGO = "chicago",
|
||||||
|
IDEOGRAPH__DIGITAL = "ideographDigital",
|
||||||
|
JAPANESE_COUNTING = "japaneseCounting",
|
||||||
|
AIUEO = "aiueo",
|
||||||
|
IROHA = "iroha",
|
||||||
|
DECIMAL_FULL_WIDTH = "decimalFullWidth",
|
||||||
|
DECIMAL_HALF_WIDTH = "decimalHalfWidth",
|
||||||
|
JAPANESE_LEGAL = "japaneseLegal",
|
||||||
|
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand",
|
||||||
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
||||||
|
DECIMAL_FULL_WIDTH2 = "decimalFullWidth2",
|
||||||
|
AIUEO_FULL_WIDTH = "aiueoFullWidth",
|
||||||
|
IROHA_FULL_WIDTH = "irohaFullWidth",
|
||||||
|
DECIMAL_ZERO = "decimalZero",
|
||||||
|
BULLET = "bullet",
|
||||||
|
GANADA = "ganada",
|
||||||
|
CHOSUNG = "chosung",
|
||||||
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
||||||
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
||||||
DECIMAL_ZERO = "decimalZero",
|
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese",
|
||||||
LOWER_LETTER = "lowerLetter",
|
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle",
|
||||||
LOWER_ROMAN = "lowerRoman",
|
IDEOGRAPH_TRADITIONAL = "ideographTraditional",
|
||||||
|
IDEOGRAPH_ZODIAC = "ideographZodiac",
|
||||||
|
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional",
|
||||||
|
TAIWANESE_COUNTING = "taiwaneseCounting",
|
||||||
|
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional",
|
||||||
|
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand",
|
||||||
|
TAIWANESE_DIGITAL = "taiwaneseDigital",
|
||||||
|
CHINESE_COUNTING = "chineseCounting",
|
||||||
|
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified",
|
||||||
|
CHINESE_COUNTING_THOUSAND = "chineseCountingThousand",
|
||||||
|
KOREAN_DIGITAL = "koreanDigital",
|
||||||
|
KOREAN_COUNTING = "koreanCounting",
|
||||||
|
KOREAN_LEGAL = "koreanLegal",
|
||||||
|
KOREAN_DIGITAL2 = "koreanDigital2",
|
||||||
|
VIETNAMESE_COUNTING = "vietnameseCounting",
|
||||||
|
RUSSIAN_LOWER = "russianLower",
|
||||||
|
RUSSIAN_UPPER = "russianUpper",
|
||||||
NONE = "none",
|
NONE = "none",
|
||||||
ORDINAL_TEXT = "ordinalText",
|
NUMBER_IN_DASH = "numberInDash",
|
||||||
UPPER_LETTER = "upperLetter",
|
HEBREW1 = "hebrew1",
|
||||||
UPPER_ROMAN = "upperRoman",
|
HEBREW2 = "hebrew2",
|
||||||
|
ARABIC_ALPHA = "arabicAlpha",
|
||||||
|
ARABIC_ABJAD = "arabicAbjad",
|
||||||
|
HINDI_VOWELS = "hindiVowels",
|
||||||
|
HINDI_CONSONANTS = "hindiConsonants",
|
||||||
|
HINDI_NUMBERS = "hindiNumbers",
|
||||||
|
HINDI_COUNTING = "hindiCounting",
|
||||||
|
THAI_LETTERS = "thaiLetters",
|
||||||
|
THAI_NUMBERS = "thaiNumbers",
|
||||||
|
THAI_COUNTING = "thaiCounting",
|
||||||
|
BAHT_TEXT = "bahtText",
|
||||||
|
DOLLAR_TEXT = "dollarText",
|
||||||
|
CUSTOM = "custom",
|
||||||
}
|
}
|
||||||
|
|
||||||
class LevelAttributes extends XmlAttributeComponent<{
|
class LevelAttributes extends XmlAttributeComponent<{
|
||||||
|
@ -1,16 +1,51 @@
|
|||||||
// http://officeopenxml.com/WPalignment.php
|
// http://officeopenxml.com/WPalignment.php
|
||||||
// http://officeopenxml.com/WPtableAlignment.php
|
// http://officeopenxml.com/WPtableAlignment.php
|
||||||
|
// http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_Jc">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="start"/>
|
||||||
|
// <xsd:enumeration value="center"/>
|
||||||
|
// <xsd:enumeration value="end"/>
|
||||||
|
// <xsd:enumeration value="both"/>
|
||||||
|
// <xsd:enumeration value="mediumKashida"/>
|
||||||
|
// <xsd:enumeration value="distribute"/>
|
||||||
|
// <xsd:enumeration value="numTab"/>
|
||||||
|
// <xsd:enumeration value="highKashida"/>
|
||||||
|
// <xsd:enumeration value="lowKashida"/>
|
||||||
|
// <xsd:enumeration value="thaiDistribute"/>
|
||||||
|
// <xsd:enumeration value="left"/>
|
||||||
|
// <xsd:enumeration value="right"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
export enum AlignmentType {
|
export enum AlignmentType {
|
||||||
|
/** Align Start */
|
||||||
START = "start",
|
START = "start",
|
||||||
END = "end",
|
/** Align Center */
|
||||||
CENTER = "center",
|
CENTER = "center",
|
||||||
|
/** End */
|
||||||
|
END = "end",
|
||||||
|
/** Justified */
|
||||||
BOTH = "both",
|
BOTH = "both",
|
||||||
JUSTIFIED = "both",
|
/** Medium Kashida Length */
|
||||||
|
MEDIUM_KASHIDA = "mediumKashida",
|
||||||
|
/** Distribute All Characters Equally */
|
||||||
DISTRIBUTE = "distribute",
|
DISTRIBUTE = "distribute",
|
||||||
|
/** Align to List Tab */
|
||||||
|
NUM_TAB = "numTab",
|
||||||
|
/** Widest Kashida Length */
|
||||||
|
HIGH_KASHIDA = "highKashida",
|
||||||
|
/** Low Kashida Length */
|
||||||
|
LOW_KASHIDA = "lowKashida",
|
||||||
|
/** Thai Language Justification */
|
||||||
|
THAI_DISTRIBUTE = "thaiDistribute",
|
||||||
|
/** Align Left */
|
||||||
LEFT = "left",
|
LEFT = "left",
|
||||||
|
/** Align Right */
|
||||||
RIGHT = "right",
|
RIGHT = "right",
|
||||||
|
/** Justified */
|
||||||
|
JUSTIFIED = "both",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> {
|
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> {
|
||||||
|
@ -4,6 +4,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
export enum LineRuleType {
|
export enum LineRuleType {
|
||||||
AT_LEAST = "atLeast",
|
AT_LEAST = "atLeast",
|
||||||
EXACTLY = "exactly",
|
EXACTLY = "exactly",
|
||||||
|
EXACT = "exact",
|
||||||
AUTO = "auto",
|
AUTO = "auto",
|
||||||
}
|
}
|
||||||
export interface ISpacingProperties {
|
export interface ISpacingProperties {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
|
import { SpaceType } from "@file/shared";
|
||||||
|
|
||||||
import { Text } from "./text";
|
import { Text } from "./text";
|
||||||
|
|
||||||
@ -13,5 +14,26 @@ describe("Text", () => {
|
|||||||
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds the passed in text to the component with options", () => {
|
||||||
|
const t = new Text({
|
||||||
|
text: " this is\n text",
|
||||||
|
space: SpaceType.PRESERVE,
|
||||||
|
});
|
||||||
|
const f = new Formatter().format(t);
|
||||||
|
expect(f).to.deep.equal({
|
||||||
|
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds the passed in text to the component with options and sets default space type", () => {
|
||||||
|
const t = new Text({
|
||||||
|
text: " this is\n text",
|
||||||
|
});
|
||||||
|
const f = new Formatter().format(t);
|
||||||
|
expect(f).to.deep.equal({
|
||||||
|
"w:t": [{ _attr: { "xml:space": "default" } }, " this is\n text"],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,11 +3,31 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
|
|
||||||
import { TextAttributes } from "../text-attributes";
|
import { TextAttributes } from "../text-attributes";
|
||||||
|
|
||||||
export class Text extends XmlComponent {
|
// <xsd:complexType name="CT_Text">
|
||||||
public constructor(text: string) {
|
// <xsd:simpleContent>
|
||||||
super("w:t");
|
// <xsd:extension base="s:ST_String">
|
||||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
// <xsd:attribute ref="xml:space" use="optional" />
|
||||||
|
// </xsd:extension>
|
||||||
|
// </xsd:simpleContent>
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
this.root.push(text);
|
interface ITextOptions {
|
||||||
|
readonly space?: SpaceType;
|
||||||
|
readonly text?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Text extends XmlComponent {
|
||||||
|
public constructor(options: string | ITextOptions) {
|
||||||
|
super("w:t");
|
||||||
|
|
||||||
|
if (typeof options === "string") {
|
||||||
|
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||||
|
this.root.push(options);
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
this.root.push(new TextAttributes({ space: options.space ?? SpaceType.DEFAULT }));
|
||||||
|
this.root.push(options.text);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ export class SymbolRun extends Run {
|
|||||||
if (typeof options === "string") {
|
if (typeof options === "string") {
|
||||||
super({});
|
super({});
|
||||||
this.root.push(new Symbol(options));
|
this.root.push(new Symbol(options));
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
super(options);
|
super(options);
|
||||||
|
@ -19,6 +19,7 @@ export enum UnderlineType {
|
|||||||
WAVE = "wave",
|
WAVE = "wave",
|
||||||
WAVYHEAVY = "wavyHeavy",
|
WAVYHEAVY = "wavyHeavy",
|
||||||
WAVYDOUBLE = "wavyDouble",
|
WAVYDOUBLE = "wavyDouble",
|
||||||
|
NONE = "none",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Underline extends XmlComponent {
|
export class Underline extends XmlComponent {
|
||||||
|
Reference in New Issue
Block a user