跳到主要内容

GetShd

从当前文本属性获取文本底纹。

继承自 ApiTextPr.GetShd

示例

读取文档中应用于文本运行的背景底纹。

// How do I find out what shading color and pattern are set on a piece of text in a document?

// Copy the shading from one text run and apply it to another run in a document.

let doc = Api.GetDocument();
let firstParagraph = doc.GetElement(0);

let myNewRunStyle = doc.CreateStyle('My New Run Style', 'run');
let styleTextPr = myNewRunStyle.GetTextPr();
styleTextPr.SetCaps(true);
styleTextPr.SetFontFamily('Calibri Light');

let firstRun = Api.CreateRun();
firstRun.AddText('This is just a sample text. ');
firstParagraph.AddElement(firstRun);

let secondRun = Api.CreateRun();
secondRun.SetStyle(myNewRunStyle);
secondRun.AddText('A text run with shd applied to it.');

let secondRunTextPr = secondRun.GetTextPr();
secondRunTextPr.SetShd('clear', Api.RGBA(255, 111, 61));
firstParagraph.AddElement(secondRun);

let shd = secondRunTextPr.GetShd();

let secondParagraph = Api.CreateParagraph();
let thirdRun = Api.CreateRun();
thirdRun.AddText('This run has the shading from the last run in the first paragraph.');
let thirdRunTextPr = thirdRun.GetTextPr();
thirdRunTextPr.SetShd(shd.Type, shd.Color);
secondParagraph.AddElement(thirdRun);
doc.Push(secondParagraph);