Free Support Forum - aspose.com

I used AddTable for Shapes but i can't insert text in each cell of the table- how do i do it?

1. I have used this much code that works:

Dim fileName As String = "D:\\demo1.ppt"
Dim pres As Presentation = New Presentation(fileName)
Dim slides As Slides = pres.Slides
Dim pholders As Placeholders = slides(0).Placeholders
Dim th As TextHolder = pholders(0)

th.Paragraphs(0).Portions(0).Text = "Hello World"
Response.ContentType = "application/vnd.ms-powerpoint"
Response.AppendHeader("Content-Disposition", "attachment; filename=demoppt.ppt")
Response.Flush()
Dim st As System.IO.Stream = Me.Response.OutputStream
Dim slide2 As Slide = slides(0)
Dim shape2 As Shape = slide2.Shapes.AddTable(10, 10, 5000, 3000, 5, 3)

Now i get a table in the slide as shown in attachment-1.
But i don't know how to show text in each of the cell in the table. Pl advise what code i should be using.

I tried using the below code which did not work

shape2.AddTextFrame("Cell1")

2. Also does your component support Html as input for the export to Powerpoint i.e. i want to export HTML Data to my .ppt file.

thanx.

Dear Sanjeev,

HTML export is not supported. You should do it by yourself.

Dim shape2 As Table = slide2.Shapes.AddTable(10,10,5000,3000,5,3)
Dim tfName As TextFrame = shape2.GetCell(0, 0).TextFrame
If Not tfName Is Nothing Then
tfName.Paragraphs(0).Portions(0).Text = “Cell1”
End If

Please check sources of our Aspose.PowerPoint.Northwind demo.
It shows most of available features.

Thanx,
I think it has solved my purpose.

1. Is there a way to set the fontsize for all text in a slide/presentation. I was able to set the font for the presentation with :

pres.Fonts(0).FontName = "Tahoma"

2. I am getting a distorted output for the text in the cells of the table as shown in the attached image. Pl advise how it can be made to look presentable.


thanx.

  1. You should set fontsize for each portion of text separately.
    2. Automatic table resizing to fit text is not supported yet. Estimated release date is end of September.
    Changing height of rows in a table is available.

Will this the resizing be supported end of September also

Yes, they will be ready in one time, may be a couple of days difference.

  1. I want to add a new blank slide to my presentation. how do i do?

    2. I want to add an image whose width can be adjusted to a percentage of the cell of the table in which it is contained.

    3. I also want to set the width of each individual column.
  1. First 5 methods.
    http://www.aspose.com/Products/Aspose.PowerPoint/Api/Aspose.PowerPoint.PresentationMembers.html

    2. Are you sure, MS PowerPoint can show adjusted image in table cell?

    3. SetColumnWidth
    http://www.aspose.com/Products/Aspose.PowerPoint/Api/Aspose.PowerPoint.TableMembers.html

I tried

pres.AddBodySlide()

It didnt work

What didn’t work? Please write example of you code.
What presentation you used? What result you got?


Public pres As Aspose.PowerPoint.Presentation
Private slides As slides
Private slideNo As Integer
Private RowNo As Integer
Private shape2 As Table

Public Sub Load(ByVal strServerPath As String,ByVal strTitle As String)
pres = New Presentation(strServerPath & "\Demo.ppt")
slides = pres.Slides

' pres.CloneSlide(pres.Slides(0), pres.Slides.Count)
pres.AddBodySlide()

shape2 = slides(0).Shapes.AddTable(500, 500, 5000, 500, 4, 2) ' slideNo - 1
shape2.MergeCells(shape2.GetCell(0, 0), shape2.GetCell(1, 0))
shape2.MergeCells(shape2.GetCell(1, 0), shape2.GetCell(2, 0))
shape2.MergeCells(shape2.GetCell(2, 0), shape2.GetCell(3, 0))
shape2.GetCell(0, 0).TextFrame().Paragraphs(0).Portions(0).Text = strTitle ' Title
shape2.GetCell(0, 1).TextFrame().Paragraphs(0).Portions(0).Text = "Responses"
shape2.GetCell(1, 1).TextFrame().Paragraphs(0).Portions(0).Text = "Total"
shape2.GetCell(2, 1).TextFrame().Paragraphs(0).Portions(0).Text = "Percentage of total Responses"
shape2.GetCell(3, 1).TextFrame().Paragraphs(0).Portions(0).Text = "%"
RowNo = 1
End Sub

I asked 3 questions.

  1. The code that i had sent did not work i.e. it did not generate as new Slide.

    Can you give me the code sample for adding a new slide to the presentation.

    2. The presentation i used is attached below.

    3. No new slide was generated.

Thank you. You code and demo.ppt are ok.
Did you try to save presentation after you added new slide?

I saved the presentation but did not get a new slide.

On adding pres.AddBodySlide this exception was thrown.

Exception of type System.StackOverflowException was thrown

Ok, try this code and check Result.ppt presentation:

pres = New Presentation(“Demo.ppt”)
pres.AddBodySlide()
pres.Write(“Result.ppt”)

I tried to add a picture to a cell of a table with this code:

Dim picid As Integer
picid = pres.Pictures.Add(New Picture(pres, “123.jpg”))

shape2.GetCell(2, 0).TextFrame.FillFormat.PictureId = picid

No picture is getting displayed in the ppt slide.

I have to give a presentation to my boss. So please reply asap.

At first you should set fill type:

Dim picid As Integer
picid = pres.ictures.Add(New Picture(pres, “123.jpg”))

shape2.GetCell(2,0).TextFrame.FillFormat.Type = FillType.Picture
shape2.GetCell(2,0).TextFrame.FillFormat.PictureId = picid