原創|使用教程|編輯:王香|2017-07-28 10:54:03.000|閱讀 524 次
概述:Spire.Presentation是一個專業的 PowerPoint控件,用于幫助開發人員高效地創建、讀取、編輯、轉換和打印任PPT文檔,本文介紹了如何在VB.NET中將HTML字符串附加到PPT中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Presentation 支持將HTML格式的文本插入到PowerPoint幻燈片中。
代碼演示:
Step 1:創建Presentation類的實例。
Presentation ppt = new Presentation();
Step 2:在幻燈片中插入一個自動形狀(矩形)。
IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 100));
Step 3:清除形狀中的默認段落。
shape.TextFrame.Paragraphs.Clear();
Step 4:從HTML代碼添加段落形狀,確保您的HTML片段是在和 標簽之間編寫的,否則AddFromHtml方法將無法正常工作。
string htmlText= "<html><body><p>First paragraph</p><p>Second paragraph</p></body></html>"; shape.TextFrame.Paragraphs.AddFromHtml(htmlText);
Step 5:保存至檔案。
ppt.SaveToFile("output.pptx", FileFormat.Pptx2013);
輸出:
完整代碼:
[C#]
Presentation ppt = new Presentation(); IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 100)); shape.TextFrame.Paragraphs.Clear(); string htmlText= "<html><body><p>First paragraph</p><p>Second paragraph</p></body></html>"; shape.TextFrame.Paragraphs.AddFromHtml(htmlText); ppt.SaveToFile("output.pptx", FileFormat.Pptx2013);
[VB.NET]
Presentation ppt = new Presentation(); IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 100)); shape.TextFrame.Paragraphs.Clear(); string htmlText= "<html><body><p>First paragraph</p><p>Second paragraph</p></body></html>"; shape.TextFrame.Paragraphs.AddFromHtml(htmlText); ppt.SaveToFile("output.pptx", FileFormat.Pptx2013);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn