跳到主要内容

GetVertAlign

从当前文本属性获取垂直对齐类型。

继承自 ApiTextPr.GetVertAlign

示例

读取文档中文本运行相对于基线的垂直位置。

// How do I check whether text is raised, lowered, or sitting on the baseline in a document?

// Inspect the vertical alignment of a text run to confirm whether it is subscript, superscript, or normal in a document.

let doc = Api.GetDocument();
let myNewRunStyle = doc.CreateStyle("My New Run Style", "run");
let textPr = myNewRunStyle.GetTextPr();
textPr.SetCaps(true);
textPr.SetFontFamily("Calibri Light");
let paragraph = doc.GetElement(0);
let run = Api.CreateRun();
run.AddText("This is just a sample text. ");
run.AddText("The text properties are changed and the style is added to the paragraph. ");
paragraph.AddElement(run);
run = Api.CreateRun();
run.SetStyle(myNewRunStyle);
run.AddText("This is a text run with its own style.");
textPr = run.GetTextPr();
textPr.SetVertAlign("subscript");
paragraph.AddElement(run);
paragraph = Api.CreateParagraph();
let vertAlign = textPr.GetVertAlign();
paragraph.AddText("Vertical alignment type: " + vertAlign);
doc.Push(paragraph);