Skip to content

Commit ee6db14

Browse files
serey-rothdolanmiu
andauthored
Add shading and border settings to paragraph style options. (#2955)
* Add shading and border settings to paragraph style options. * Fix prettier --------- Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
1 parent 170309a commit ee6db14

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as fs from "fs";
2+
import { BorderStyle, Document, Packer, Paragraph, TextRun } from "docx";
3+
4+
const doc = new Document({
5+
styles: {
6+
paragraphStyles: [
7+
{
8+
id: "withSingleBlackBordersAndYellowShading",
9+
name: "Paragraph Style with Black Borders and Yellow Shading",
10+
basedOn: "Normal",
11+
paragraph: {
12+
shading: {
13+
color: "#fff000",
14+
type: "solid",
15+
},
16+
border: {
17+
top: {
18+
style: BorderStyle.SINGLE,
19+
color: "#000000",
20+
size: 4,
21+
},
22+
bottom: {
23+
style: BorderStyle.SINGLE,
24+
color: "#000000",
25+
size: 4,
26+
},
27+
left: {
28+
style: BorderStyle.SINGLE,
29+
color: "#000000",
30+
size: 4,
31+
},
32+
right: {
33+
style: BorderStyle.SINGLE,
34+
color: "#000000",
35+
size: 4,
36+
},
37+
},
38+
},
39+
},
40+
],
41+
},
42+
sections: [
43+
{
44+
children: [
45+
new Paragraph({
46+
style: "withSingleBlackBordersAndYellowShading",
47+
children: [
48+
new TextRun({
49+
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
50+
}),
51+
],
52+
}),
53+
],
54+
},
55+
],
56+
});
57+
58+
Packer.toBuffer(doc).then((buffer) => {
59+
fs.writeFileSync("My Document.docx", buffer);
60+
});

src/file/paragraph/properties.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export type ILevelParagraphStylePropertiesOptions = {
3838
};
3939

4040
export type IParagraphStylePropertiesOptions = {
41+
readonly border?: IBordersOptions;
42+
readonly shading?: IShadingAttributesProperties;
4143
readonly numbering?:
4244
| {
4345
readonly reference: string;
@@ -49,7 +51,6 @@ export type IParagraphStylePropertiesOptions = {
4951
} & ILevelParagraphStylePropertiesOptions;
5052

5153
export type IParagraphPropertiesOptions = {
52-
readonly border?: IBordersOptions;
5354
readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
5455
readonly bidirectional?: boolean;
5556
readonly pageBreakBefore?: boolean;
@@ -58,7 +59,6 @@ export type IParagraphPropertiesOptions = {
5859
readonly bullet?: {
5960
readonly level: number;
6061
};
61-
readonly shading?: IShadingAttributesProperties;
6262
readonly widowControl?: boolean;
6363
readonly frame?: IFrameOptions;
6464
readonly suppressLineNumbers?: boolean;

0 commit comments

Comments
 (0)