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:
60
demo/95-paragraph-style-with-shading-and-borders.ts
Normal file
60
demo/95-paragraph-style-with-shading-and-borders.ts
Normal 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);
|
||||
});
|
@ -38,6 +38,8 @@ export type ILevelParagraphStylePropertiesOptions = {
|
||||
};
|
||||
|
||||
export type IParagraphStylePropertiesOptions = {
|
||||
readonly border?: IBordersOptions;
|
||||
readonly shading?: IShadingAttributesProperties;
|
||||
readonly numbering?:
|
||||
| {
|
||||
readonly reference: string;
|
||||
@ -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;
|
||||
@ -58,7 +59,6 @@ export type IParagraphPropertiesOptions = {
|
||||
readonly bullet?: {
|
||||
readonly level: number;
|
||||
};
|
||||
readonly shading?: IShadingAttributesProperties;
|
||||
readonly widowControl?: boolean;
|
||||
readonly frame?: IFrameOptions;
|
||||
readonly suppressLineNumbers?: boolean;
|
||||
|
Reference in New Issue
Block a user