Aspose Slides Table Cell插入HTML内容

时间:2014-07-25 07:17:03

标签: c#-4.0 aspose aspose-slides

我正在使用Aspose幻灯片在我的应用程序中生成PPT,我遇到了需要将 HTML 文本插入Table Cell的情况,我验证了所有博客都没有人给出答案。如果有人知道,请告诉我。在此先感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用与每个单元格关联的TextFrame段落,使用Aspose.Slides for .NET插入HTML。请检查以下代码:

//Instantiate Presentation class that represents PPTX file
using (Presentation pres = new Presentation())
{

    //Access first slide
    ISlide sld = pres.Slides[0];

   //Define columns with widths and rows with heights
   double[] dblCols = { 250, 250};
   double[] dblRows = { 150, 130, 130 };

    //Add table shape to slide
    ITable tbl = sld.Shapes.AddTable(100, 50, dblCols, dblRows);

    //Set border format for each cell
    foreach (IRow row in tbl.Rows)
        foreach (ICell cell in row)
        {
            cell.BorderTop.FillFormat.FillType = FillType.Solid;
            cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Red;
            cell.BorderTop.Width = 5;

            cell.BorderBottom.FillFormat.FillType = FillType.Solid;
            cell.BorderBottom.FillFormat.SolidFillColor.Color = Color.Red;
            cell.BorderBottom.Width = 5;

            cell.BorderLeft.FillFormat.FillType = FillType.Solid;
            cell.BorderLeft.FillFormat.SolidFillColor.Color = Color.Red;
            cell.BorderLeft.Width = 5;

            cell.BorderRight.FillFormat.FillType = FillType.Solid;
            cell.BorderRight.FillFormat.SolidFillColor.Color = Color.Red;
            cell.BorderRight.Width = 5;
        }

    //Adding html text in text frame
    tbl[0, 0].TextFrame.Paragraphs.AddFromHtml(@"<html><body><p><b>This text is bold</b></p>
    <p><i>This text is italic</i></p><p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
    </body></html>");

    //Write PPTX to Disk
    pres.Save("d:\\data\\table_html.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}

P.S。我是Aspose的社交媒体开发人员。