Skip to content

Add shading and border settings to paragraph style options. #2955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions demo/95-paragraph-style-with-shading-and-borders.ts
Original file line number Diff line number Diff line change
@@ -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);
});
4 changes: 2 additions & 2 deletions src/file/paragraph/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type ILevelParagraphStylePropertiesOptions = {
};

export type IParagraphStylePropertiesOptions = {
readonly border?: IBordersOptions;
readonly shading?: IShadingAttributesProperties;
readonly numbering?:
| {
readonly reference: string;
Expand All @@ -49,7 +51,6 @@ export type IParagraphStylePropertiesOptions = {
} & ILevelParagraphStylePropertiesOptions;

export type IParagraphPropertiesOptions = {
readonly border?: IBordersOptions;
readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
readonly bidirectional?: boolean;
readonly pageBreakBefore?: boolean;
Expand All @@ -58,7 +59,6 @@ export type IParagraphPropertiesOptions = {
readonly bullet?: {
readonly level: number;
};
readonly shading?: IShadingAttributesProperties;
readonly widowControl?: boolean;
readonly frame?: IFrameOptions;
readonly suppressLineNumbers?: boolean;
Expand Down
Loading