Compare commits
1 Commits
8.2.3
...
feat/parag
Author | SHA1 | Date | |
---|---|---|---|
5e87e4fb0b |
31
demo/57-paragraph-run-styles.ts
Normal file
31
demo/57-paragraph-run-styles.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Add Run styles across the whole Paragraph
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
runStyle: {
|
||||||
|
size: 100,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -12,6 +12,7 @@ import { HeadingLevel, Style } from "./formatting/style";
|
|||||||
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
|
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
|
||||||
import { NumberProperties } from "./formatting/unordered-list";
|
import { NumberProperties } from "./formatting/unordered-list";
|
||||||
import { OutlineLevel } from "./links";
|
import { OutlineLevel } from "./links";
|
||||||
|
import { IRunPropertiesOptions, RunProperties } from "./run";
|
||||||
import { Shading } from "./run/formatting";
|
import { Shading } from "./run/formatting";
|
||||||
|
|
||||||
export interface IParagraphStylePropertiesOptions {
|
export interface IParagraphStylePropertiesOptions {
|
||||||
@ -51,6 +52,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
|||||||
readonly fill: string;
|
readonly fill: string;
|
||||||
readonly color: string;
|
readonly color: string;
|
||||||
};
|
};
|
||||||
|
readonly runStyle?: IRunPropertiesOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
@ -142,6 +144,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
if (options.shading) {
|
if (options.shading) {
|
||||||
this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
|
this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.runStyle) {
|
||||||
|
this.push(new RunProperties(options.runStyle));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public push(item: XmlComponent): void {
|
public push(item: XmlComponent): void {
|
||||||
|
Reference in New Issue
Block a user