PPT控件Spire.Presentation 教程:在VB.NET中將HTML字符串附加到PPT中

Spire.Presentation 支持將HTML格式的文本插入到PowerPoint幻燈片中。html

代碼演示:ide

Step 1:建立Presentation類的實例。orm

Presentation ppt = new Presentation();

Step 2:在幻燈片中插入一個自動形狀(矩形)。htm

IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 100));

Step 3:清除形狀中的默認段落。blog

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:保存至檔案。get

ppt.SaveToFile("output.pptx", FileFormat.Pptx2013);

輸出:string

圖片1

完整代碼:io

[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);

慧都控件網

相關文章
相關標籤/搜索