Free Support Forum - aspose.com

Manage Tables with Powerpoint 2002 (XP)

Hi,

I'am trying to create a powerpoint dynamically and for that I need to draw a table.

I use a powerpoint template that I modify and then save. I have two solutions for my table
1- I create a template from scratch and fill it
2- I create a table in the template and I modify it

Neither of these solutions works :/

Solution 1:
If i create a new table as explained in the Wiki, my table is too big and I can't control its border, font size, etc

Solution 2:
If I create a table in the template, I can't ajust its alternativeText. I don't have the panel to add it. It's ok for image, shapes, etc but not for table. What can I do?

I tried something else:
I opened my template, add a table, edit its alternativetext and then save the template.
I open manually the template and change the layout and the font size of the table and save

Then, I reopen the template through C# and when I tried a findshape, my table does not have AlternativeText property.

Is-it because I use an "old" (not so much :D) version of powerpoint? is there any other trick to do what I want to do?

Regards,

Dear bobbob601,

Thanks for considering Aspose.Slides for NET.

I suppose, you are using Aspose.Slides 2.7.0.0 or later.

You can definitely control border and font. To get access to table border, please see this link.

http://www.aspose.com/Community/Forums/thread/99348.aspx

To change the font height, you will have to set the Portion.FontHeight property

e.g

srcTbl.GetCell(0,0).TextFrame.Paragraphs[0].Portions[0].FontHeight=12;

The code snippet below sets the font of first cell to 12

* * * * * * * * * * * * * * * * * * * * * *

I can see this problem, so you cannot use Slide.FindShape method.

For it, you will have to iterate all shapes and check the shape type until you get the reference to a table. e.g

Aspose.Slides.Table srcTable=null;

foreach (Shape shp in srcSld.Shapes)

{

if (shp is Aspose.Slides.Table)

{

srcTable=shp as Aspose.Slides.Table;

break;

}

}

"I suppose, you are using Aspose.Slides 2.7.0.0 or later"
2.7.3.0

"I can see this problem, so you cannot use Slide.FindShape method."
Ok but why does the wiki say to use this method if it is not possible? I checked with Office2007, it's exactly the same problem.
In be totally honest, the wiki says to use the alternativetext "table.AlternativeText.Equals("myTable"))" but I can't specify an alternativetext in design mode :-/

My problem is that each slide has a lot of tables and I don't know how to aim a specific already-existing table.

Thank you for the link and the FontHeight , I read the wiki without finding that

Actually, I have also checked it on PowerPoint 2002, so I am not sure, later versions have this facility of setting alternative text at design time for tables.

But my finding is that, if we set the alternative text by Aspose.Slides on the table, write the presentation back and read it again, we can access it using Shape.FindShape method. i.e

Presentation srcPres = new Presentation();

Slide sld = srcPres.GetSlideByPosition(1);

Table tbl = sld.Shapes.AddTable(500, 500, 5000, 3000, 3, 2);

tbl.AlternativeText = "mytable";

MemoryStream ms = new MemoryStream();

srcPres.Write(@"c:\outPres.ppt");

ms.Position = 0;

Presentation srcPres2 = new Presentation(@"c:\outPres.ppt");

sld = srcPres2.GetSlideByPosition(1);

Shape shp = sld.FindShape("mytable");

Do you know how to set font type for each cell? I have requirement to change font type for different cells. Thanks

Hi Giang,


Please use the following sample code to serve the purpose. Please share, if I may help you further in this regards.

public static void setTableForamt()
{
//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();

//Accessing a slide using its slide position
Slide slide = pres.GetSlideByPosition(1);

//Setting table parameters
int xPosition = 880;
int yPosition = 1400;
int tableWidth = 4000;
int tableHeight = 500;
int columns = 4;
int rows = 4;
double borderWidth = 2;


//Adding a new table to the slide using specified table parameters
Table table = slide.Shapes.AddTable(xPosition, yPosition, tableWidth, tableHeight,
columns, rows, borderWidth, Color.Blue);
//Setting the alternative text for the table that can help in future to find
//and identify this specific table
table.AlternativeText = “myTable”;

//Accessing the text frame of the first cell of the first row in the table
TextFrame tf = table.GetCell(0, 0).TextFrame;
tf.Paragraphs.Clear();
//If text frame is not null then add some text to the cell
if (tf != null)
{
Paragraph para = new Paragraph();

//Getting the first paragraph of the text holder

//Accessing the first portion of the paragraph
Portion port = new Portion();

//Setting the font to bold
port.FontBold = true;

//Setting the font to be underlined
port.FontUnderline = true;

//Setting the font to be embossed
port.FontEmbossed = true;

//Setting the font to be italic
port.FontItalic = true;

//Enabling the font shadow
port.FontShadow = true;

//Setting the font color to green
port.FontColor = Color.Green;

//Setting the font height to 55
port.FontHeight = 15;

port.Text = "Welcome to Aspose.Slides ";

para.Portions.Add(port);
tf.Paragraphs.Add(para);
para.HasBullet = false;
}

TextFrame tf2 = table.GetCell(0, 1).TextFrame;
tf2.Paragraphs.Clear();
//If text frame is not null then add some text to the cell
if (tf2 != null)
{
Paragraph para = new Paragraph();

//Getting the first paragraph of the text holder

//Accessing the first portion of the paragraph
Portion port = new Portion();

//Setting the font to bold
port.FontBold = true;

//Setting the font to be underlined
port.FontUnderline = true;

//Setting the font to be embossed
port.FontEmbossed = true;

//Setting the font to be italic
port.FontItalic = true;

//Enabling the font shadow
port.FontShadow = true;

//Setting the font color to green
port.FontColor = Color.Red;

//Setting the font height to 55
port.FontHeight = 25;

port.Text = "Second cell ";

para.Portions.Add(port);
tf2.Paragraphs.Add(para);
para.HasBullet = false;

}

Many Thanks,