0

我正在使用 Aspose 幻灯片在我的应用程序中生成 PPT,我遇到了需要将HTML文本插入表格单元格的情况,我验证了所有博客都没有人给我答案。如果有人知道这里,请告诉我。提前致谢。

4

1 回答 1

1

您可以使用与每个单元格关联的 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);
}

PS 我在 Aspose 担任社交媒体开发人员。

于 2014-07-25T13:48:58.180 回答