Using table placeholder programmatically

G

Guest

Hi,
I don't know if it's the right newsgroup...
However I'm trying to add a slide to a ppt file via C#/VB. I added a slide
with table layout, so I expect myself to have 2 placeholders, one for the
title and one for the table, and it is right.
I can modify the title, but the other placeholder (debugging I can see it is
a table placeholder) doesn't have a table inside it... So i try to add a
table to shapes collection and then assign this table to the table property
of the placeholder, but it's read-only.

Definitely, my question is:
"Is it possible to use the table placeholder to add a table at runtime (so
I've the right measures for left, top, widht and height) or I've to set a
blank layout and thena add a table??"

This is some code:
Microsoft.Office.Interop.PowerPoint.ApplicationClass ac = new
ApplicationClass();
ac.ShowWindowsInTaskbar =
Microsoft.Office.Core.MsoTriState.msoFalse;
//ac.WindowState = PpWindowState.ppWindowMinimized;
//ac.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
Presentation pptPresentation =
ac.Presentations.Open("C:\\Progetti\\Gestione Comitato
Investimenti\\Bozza_presentazione.ppt",
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse);
Slide firme =
pptPresentation.Slides.Add(pptPresentation.Slides.Count + 1,
PpSlideLayout.ppLayoutTable);
//firme.ApplyTemplate("C:\\Progetti\\Gestione Comitato
Investimenti\\Presentation1.pot");
firme.Name = "Firme Calligrafiche";
firme.Shapes.Title.TextFrame.TextRange.Text = "Firme
Callografiche";
Shape placheholderTable = firme.Shapes.Placeholders[2];
Shape tableFirme = firme.Shapes.AddTable(6, 2,
placeholderTable.Left, placeholderTable.Top, placeholderTable.Width,
placeholderTable.Height);
tableFirme.Table.TableDirection =
PpDirection.ppDirectionLeftToRight;
tableFirme.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text =
"Proposer";
placeholderTable.Table = tableFirme.Table;
 
S

Steve Rindsberg

Napoleone1981 said:
Hi,
I don't know if it's the right newsgroup...
However I'm trying to add a slide to a ppt file via C#/VB. I added a slide
with table layout, so I expect myself to have 2 placeholders, one for the
title and one for the table, and it is right.
I can modify the title, but the other placeholder (debugging I can see it is
a table placeholder) doesn't have a table inside it... So i try to add a
table to shapes collection and then assign this table to the table property
of the placeholder, but it's read-only.

Definitely, my question is:
"Is it possible to use the table placeholder to add a table at runtime (so
I've the right measures for left, top, widht and height) or I've to set a
blank layout and thena add a table??"

You could get a reference to the placeholder and then add your table as a new
shape using the coordinates of the placeholder shape to position the table,
then delete the placeholder shape.


This is some code:
Microsoft.Office.Interop.PowerPoint.ApplicationClass ac = new
ApplicationClass();
ac.ShowWindowsInTaskbar =
Microsoft.Office.Core.MsoTriState.msoFalse;
//ac.WindowState = PpWindowState.ppWindowMinimized;
//ac.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
Presentation pptPresentation =
ac.Presentations.Open("C:\\Progetti\\Gestione Comitato
Investimenti\\Bozza_presentazione.ppt",
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse);
Slide firme =
pptPresentation.Slides.Add(pptPresentation.Slides.Count + 1,
PpSlideLayout.ppLayoutTable);
//firme.ApplyTemplate("C:\\Progetti\\Gestione Comitato
Investimenti\\Presentation1.pot");
firme.Name = "Firme Calligrafiche";
firme.Shapes.Title.TextFrame.TextRange.Text = "Firme
Callografiche";
Shape placheholderTable = firme.Shapes.Placeholders[2];
Shape tableFirme = firme.Shapes.AddTable(6, 2,
placeholderTable.Left, placeholderTable.Top, placeholderTable.Width,
placeholderTable.Height);
tableFirme.Table.TableDirection =
PpDirection.ppDirectionLeftToRight;
tableFirme.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text =
"Proposer";
placeholderTable.Table = tableFirme.Table;
 
Top