Aspose Slides Table Cell Insert HTML content

1.8k views Asked by At

I am working with Aspose slides to generate PPT in my application, I ran into a situation where I need to insert HTML text into Table Cell, I verified all blogs no one given answer to me. If any body know here please let me know. Thanks In advance.

1

There are 1 answers

2
Nausherwan Aslam On

You can use the TextFrame's paragraph associated with each cell to insert HTML using Aspose.Slides for .NET. Check the following code:

//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. I am working as social media developer at Aspose.