我正在尝试以编程方式将内容插入到 Powerpoint 的注释页面中。同一行上会有不同颜色的文本。我只是通过段落让它工作,但这样做会使它们出现在不同的行上。
这是我尝试过的:
var slideRange = Application.ActivePresentation.Slides;
slideRange[1].NotesPage.Shapes[2].TextFrame.TextRange.Paragraphs(1).Font.Color.RGB = Color.Black;
slideRange[1].NotesPage.Shapes[2].TextFrame.TextRange.Paragraphs(1).Text = "word1\r";
slideRange[1].NotesPage.Shapes[2].TextFrame.TextRange.Paragraphs(2).Font.Color.RGB = Color.Gray;
slideRange[1].NotesPage.Shapes[2].TextFrame.TextRange.Paragraphs(2).Text = "word2\r";
这两个单词以不同的颜色显示,但我希望它们位于同一行。
我尝试通过 TextRange (TextRange.Font.Color) 设置颜色,但这似乎是只读属性。
显示我希望实现的目标的图片 https://i.stack.imgur.com/zlCDz.png
所以我花了相当多的时间来寻找更优雅的解决方案......但这是我发现的最好的......
这假设您的文本格式为 HTML,但如果您已有 RTF 格式,则需要从一个标记部分开始。
var html = "<!DOCTYPE html><html><head></head><body><style type=\"text/css\">.SQLCode{font-size:13px;font-weight:bold;font-family:monospace;;white-space:pre;-o-tab-size:4;-moz-tab-size:4;-webkit-tab-size:4;}.SQLComment{color:#00AA00;}.SQLString{color:#AA0000;}.SQLFunction{color:#AA00AA;}.SQLKeyword{color:#0000AA;}.SQLOperator{color:#777777;}.SQLErrorHighlight{background-color:#FFFF00;}</style><pre class=\"SQLCode\"><span class=\"SQLComment\">--Example Commend</span><span class=\"SQLKeyword\">SELECT</span><span class=\"SQLKeyword\">TOP</span> 1 <span class=\"SQLFunction\">COALESCE</span><span class=\"SQLOperator\">(</span>ASPU<span class=\"SQLOperator\">.</span>MobileAlias<span class=\"SQLOperator\">,</span> ASPU<span class=\"SQLOperator\">.</span>UserName<span class=\"SQLOperator\">)</span><span class=\"SQLKeyword\">AS</span> UName<span class=\"SQLKeyword\">FROM</span> dbo<span class=\"SQLOperator\">.</span>aspnet_Users ASPU</pre></body></html>";
var title = "Header Text";
if (!string.IsNullOrWhiteSpace(html))
{
var web = new WebBrowser();
web.CreateControl();
web.DocumentText = html;
while (web.DocumentText != html)
{
System.Windows.Forms.Application.DoEvents();
}
web.Document.ExecCommand("SelectAll", false, null);
web.Document.ExecCommand("Copy", false,
//Start here if you already have it in RTF.
var rtf = Clipboard.GetData(DataFormats.Rtf) as string;
if (!string.IsNullOrWhiteSpace(rtf))
{
slide = ppt.Slides.AddSlide(ppt.Slides.Count + 1, ppt.SlideMaster.CustomLayouts[1]);
slide.Layout = PpSlideLayout.ppLayoutTextAndObject;
slide.Shapes.Title.TextFrame.TextRange.Text = title;
slide.Select();
slide.Shapes[2].Select();
Globals.ThisAddIn.Application.CommandBars.ExecuteMso("PasteSourceFormatting");
System.Windows.Forms.Application.DoEvents();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)