跳到主要内容

SetSpacingLine

设置段落行距。

如果 sLineRule 参数的值为 "atLeast" 或 "exact",则 nLine 的值将被解释为磅的二十分之一。如果 sLineRule 参数的值为 "auto",则 nLine 参数的值将被解释为行的 240 分之一。

继承自 ApiParaPr.SetSpacingLine。

语法​

expression.SetSpacingLine(nLine, sLineRule);

expression - 表示 ApiParagraph 类的变量。

参数​

名称必需/可选数据类型默认值描述
nLine必需twips | line240行距值,以磅的二十分之一(1/1440 英寸)或行的 240 分之一为单位。
sLineRule必需"auto" | "atLeast" | "exact"确定行距度量单位的规则。

返回值​

boolean

示例​

在演示文稿中设置段落之间的行距。

// How do I adjust the spacing between lines of text in a presentation?

// Apply different line spacing values to paragraphs in a presentation.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const gs1 = Api.CreateGradientStop(Api.RGB(255, 213, 191), 0);
const gs2 = Api.CreateGradientStop(Api.RGB(255, 111, 61), 100000);
const fill = Api.CreateRadialGradientFill([gs1, gs2]);
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("flowChartMagneticTape", 300 * 36000, 130 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);

const docContent = shape.GetDocContent();
let paragraph = docContent.GetElement(0);
paragraph.SetSpacingLine(2 * 240, "auto");
paragraph.AddText("Paragraph 1. Spacing: 2 times of a common paragraph line spacing.");
paragraph.AddLineBreak();
paragraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
paragraph.AddText("These sentences are used to add lines for demonstrative purposes. ");

paragraph = Api.CreateParagraph();
paragraph.SetSpacingLine(200, "exact");
paragraph.AddText("Paragraph 2. Spacing: exact 10 points.");
paragraph.AddLineBreak();
paragraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
paragraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
docContent.Push(paragraph);
slide.AddObject(shape);