我正在尝试以编程方式将内容插入到Powerpoint的Notes页面中。同一行上会有不同的彩色文字。我只是通过段落让它工作,但这样做会使它们出现在不同的行上。
这就是我的尝试:
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)设置颜色,但这似乎是一个只读属性。
答案 0 :(得分:0)
所以我花了相当多的时间寻找更优雅的解决方案.....但这是我发现的最好的.... 这假定您的文本格式为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();
}
}