VSTO Powerpoint Notes Page - Different colored words on same line

后端 未结 1 1085
梦谈多话
梦谈多话 2021-01-22 12:40

I am trying to insert content into the Notes Page of Powerpoint programmatically. There will be different colored text on the same line. I have only gotten it to work via paragr

相关标签:
1条回答
  • 2021-01-22 13:13

    So I've spent a fair bit of time on this looking for a more elegant solution..... but this is the best I have found.... This assumes that you have your text formatted in HTML, but there is a marked section to start if you already have a RTF format.

    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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题