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>
This commit is contained in:
Serey Roth
2025-02-16 10:33:21 -08:00
committed by GitHub
parent 170309a7ed
commit ee6db1429a
2 changed files with 62 additions and 2 deletions

View File

@ -0,0 +1,60 @@
import * as fs from "fs";
import { BorderStyle, Document, Packer, Paragraph, TextRun } from "docx";
const doc = new Document({
styles: {
paragraphStyles: [
{
id: "withSingleBlackBordersAndYellowShading",
name: "Paragraph Style with Black Borders and Yellow Shading",
basedOn: "Normal",
paragraph: {
shading: {
color: "#fff000",
type: "solid",
},
border: {
top: {
style: BorderStyle.SINGLE,
color: "#000000",
size: 4,
},
bottom: {
style: BorderStyle.SINGLE,
color: "#000000",
size: 4,
},
left: {
style: BorderStyle.SINGLE,
color: "#000000",
size: 4,
},
right: {
style: BorderStyle.SINGLE,
color: "#000000",
size: 4,
},
},
},
},
],
},
sections: [
{
children: [
new Paragraph({
style: "withSingleBlackBordersAndYellowShading",
children: [
new TextRun({
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.",
}),
],
}),
],
},
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

View File

@ -38,6 +38,8 @@ export type ILevelParagraphStylePropertiesOptions = {
}; };
export type IParagraphStylePropertiesOptions = { export type IParagraphStylePropertiesOptions = {
readonly border?: IBordersOptions;
readonly shading?: IShadingAttributesProperties;
readonly numbering?: readonly numbering?:
| { | {
readonly reference: string; readonly reference: string;
@ -49,7 +51,6 @@ export type IParagraphStylePropertiesOptions = {
} & ILevelParagraphStylePropertiesOptions; } & ILevelParagraphStylePropertiesOptions;
export type IParagraphPropertiesOptions = { export type IParagraphPropertiesOptions = {
readonly border?: IBordersOptions;
readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel]; readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
readonly bidirectional?: boolean; readonly bidirectional?: boolean;
readonly pageBreakBefore?: boolean; readonly pageBreakBefore?: boolean;
@ -58,7 +59,6 @@ export type IParagraphPropertiesOptions = {
readonly bullet?: { readonly bullet?: {
readonly level: number; readonly level: number;
}; };
readonly shading?: IShadingAttributesProperties;
readonly widowControl?: boolean; readonly widowControl?: boolean;
readonly frame?: IFrameOptions; readonly frame?: IFrameOptions;
readonly suppressLineNumbers?: boolean; readonly suppressLineNumbers?: boolean;