http://www.aspose.com/docs/display/slidesnet/Replacing+Text+on+a+PlaceHolder
http://www.aspose.com/docs/display/slidesnet/Replacing+Text+on+a+PlaceHolder
Hi Kostas,
I like to share that layout slides are part of master slides and Aspose.Slides allows you to clone the master slides. Once master is cloned, you can assign the layout slide of that particular master to any of your slide. Please visit this link for your convenience.
Many Thanks,
Hi Kostas,
Many Thanks,public static void AddChartPlacehoder(){PresentationEx presentation = new PresentationEx(“D:\Aspose Data\TemplatePPT.pptx”);//PresentationEx presentation = new PresentationEx();presentation.UpdateDateTimeFields = true;foreach (LayoutSlideEx layout in presentation.Masters[0].LayoutSlides){presentation.Slides.AddEmptySlide(layout);SlideEx slide = presentation.Slides[presentation.Slides.Count - 1];foreach (ShapeEx shape in slide.LayoutSlide.Shapes){if (shape.Placeholder != null){switch (shape.Placeholder.Type){default:slide.Shapes.AddAutoShape(ShapeTypeEx.RoundCornerRectangle, float.NaN, float.NaN, float.NaN, float.NaN);break;case PlaceholderTypeEx.SlideNumber:{slide.Shapes.AddAutoShape(ShapeTypeEx.RoundCornerRectangle, float.NaN, float.NaN, float.NaN, float.NaN);AutoShapeEx ashape = (AutoShapeEx)slide.Shapes[slide.Shapes.Count - 1];ashape.AddTextFrame(“text”);ashape.TextFrame.Paragraphs[0].Portions[0].AddField(FieldTypeEx.SlideNumber);}break;case PlaceholderTypeEx.DateAndTime:{slide.Shapes.AddAutoShape(ShapeTypeEx.RoundCornerRectangle, float.NaN, float.NaN, float.NaN, float.NaN);AutoShapeEx ashape = (AutoShapeEx)slide.Shapes[slide.Shapes.Count - 1];ashape.AddTextFrame(“text”);ashape.TextFrame.Paragraphs[0].Portions[0].AddField(FieldTypeEx.DateTime);}break;case PlaceholderTypeEx.Object:case PlaceholderTypeEx.Table:slide.Shapes.AddTable(float.NaN, float.NaN, new double[] { 30, 30, 30 }, new double[] { 20, 20 });break;case PlaceholderTypeEx.Picture:slide.Shapes.AddPictureFrame(ShapeTypeEx.Ellipse, float.NaN, float.NaN, float.NaN, float.NaN, null);break;case PlaceholderTypeEx.Chart:slide.Shapes.AddChart(Aspose.Slides.Pptx.Charts.ChartTypeEx.StackedLine,float.NaN,float.NaN,float.NaN,float.NaN);break;//case PlaceholderTypeEx.Diagram:// // TODO: add diagram insertion here// break;case PlaceholderTypeEx.Media:slide.Shapes.AddVideoFrame(float.NaN, float.NaN, float.NaN, float.NaN, @“video.avi”);break;}ShapeEx newShape = slide.Shapes[slide.Shapes.Count - 1];newShape.AddPlaceholder(shape.Placeholder);}}}presentation.Save(“D:\Aspose Data\placeholders.pptx”, Aspose.Slides .Export .SaveFormat .Pptx);}
That code looks interesting. Thanks! I will try it.
Also, once I find a shape with a placeholder, I could use this shape, right? E.g. add data to a chart placeholder. In that way perhaps I could keep the format settings (colors, fonts, etc) intact and not have to copy them to a new shape.
I just saw that the shape that has the placeholder is an AutoShapeEx, no matter what.
As far as I have seen, in PowerPoint you can set colors and fonts for a placeholder in a layout slide. How can I access and copy those settings?
When I use your code above, not all shapes get the format (background color, etc) specified in the layout. I wonder how they get positioned right…
I use the following (slightly modified) code, but most of the shapes (if not all) don’t get the formating of the layout (background color, etc). It seems that I can’t remove all of the old placeholders either (so, I get a textbox and there is the placeholder shape behind it…) :
PresentationEx presentation = new PresentationEx(@“C:\Users\User\Desktop\Template.pptx”);
//PresentationEx presentation = new PresentationEx();
presentation.UpdateDateTimeFields = true;
foreach (LayoutSlideEx layout in presentation.Masters[0].LayoutSlides)
{
int at = presentation.Slides.AddEmptySlide(layout);
SlideEx slide = presentation.Slides[at];
for (int i = 0; i < slide.Shapes.Count; i++) slide.Shapes.RemoveAt(0);<span style="color:blue;">foreach</span> (<span style="color:#2b91af;">ShapeEx</span> shape <span style="color:blue;">in</span> slide.LayoutSlide.Shapes) { <span style="color:blue;">if</span> (shape.Placeholder != <span style="color:blue;">null</span>) { <span style="color:blue;">switch</span> (shape.Placeholder.Type) { <span style="color:blue;">default</span>: slide.Shapes.AddAutoShape( <span style="color:#2b91af;">ShapeTypeEx</span>.RoundCornerRectangle, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN); <span style="color:blue;">break</span>; <span style="color:blue;">case</span> <span style="color:#2b91af;">PlaceholderTypeEx</span>.SlideNumber: { slide.Shapes.AddAutoShape( <span style="color:#2b91af;">ShapeTypeEx</span>.RoundCornerRectangle, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN); <span style="color:#2b91af;">AutoShapeEx</span> ashape = (<span style="color:#2b91af;">AutoShapeEx</span>)slide.Shapes[slide.Shapes.Count - 1]; ashape.AddTextFrame(<span style="color:#a31515;">"text"</span>); ashape.TextFrame.Paragraphs[0].Portions[0].AddField(<span style="color:#2b91af;">FieldTypeEx</span>.SlideNumber); } <span style="color:blue;">break</span>; <span style="color:blue;">case</span> <span style="color:#2b91af;">PlaceholderTypeEx</span>.DateAndTime: { slide.Shapes.AddAutoShape( <span style="color:#2b91af;">ShapeTypeEx</span>.RoundCornerRectangle, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN); <span style="color:#2b91af;">AutoShapeEx</span> ashape = (<span style="color:#2b91af;">AutoShapeEx</span>)slide.Shapes[slide.Shapes.Count - 1]; ashape.AddTextFrame(<span style="color:#a31515;">"text"</span>); ashape.TextFrame.Paragraphs[0].Portions[0].AddField(<span style="color:#2b91af;">FieldTypeEx</span>.DateTime); } <span style="color:blue;">break</span>; <span style="color:blue;">case</span> <span style="color:#2b91af;">PlaceholderTypeEx</span>.Object: <span style="color:blue;">case</span> <span style="color:#2b91af;">PlaceholderTypeEx</span>.Table: slide.Shapes.AddTable( <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">new</span> <span style="color:blue;">double</span>[] { 30, 30, 30 }, <span style="color:blue;">new</span> <span style="color:blue;">double</span>[] { 20, 20 }); <span style="color:blue;">break</span>; <span style="color:blue;">case</span> <span style="color:#2b91af;">PlaceholderTypeEx</span>.Picture: slide.Shapes.AddPictureFrame( <span style="color:#2b91af;">ShapeTypeEx</span>.Ellipse, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">null</span>); <span style="color:blue;">break</span>; <span style="color:blue;">case</span> <span style="color:#2b91af;">PlaceholderTypeEx</span>.Chart: slide.Shapes.AddChart( Aspose.Slides.Pptx.Charts.<span style="color:#2b91af;">ChartTypeEx</span>.StackedLine, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN); <span style="color:blue;">break</span>; <span style="color:green;">//case PlaceholderTypeEx.Diagram:</span> <span style="color:green;">// // </span><span style="font-weight:bold;color:darkblue;">TODO: add diagram insertion here</span> <span style="color:green;">// break;</span> <span style="color:blue;">case</span> <span style="color:#2b91af;">PlaceholderTypeEx</span>.Media: slide.Shapes.AddVideoFrame(<span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:blue;">float</span>.NaN, <span style="color:#a31515;">@"video.avi"</span>); <span style="color:blue;">break</span>; } <span style="color:#2b91af;">ShapeEx</span> newShape = slide.Shapes[slide.Shapes.Count - 1]; newShape.AddPlaceholder(shape.Placeholder); } } } <span style="color:blue;">string</span> str = <span style="color:#a31515;">@"C:\Users\</span><span style="color: rgb(163, 21, 21);">User</span><span style="color: rgb(163, 21, 21);">\Desktop\Output2.pptx"</span>;<br> presentation.Save(str, Aspose.Slides.Export.<span style="color:#2b91af;">SaveFormat</span>.Pptx);
But the new shapes go to the right place without any placement code and this makes me curious.
Why doesn’t this work right???
What should I do if I want to copy the formating (font, background color, border) of a placeholder into my new shape?
And is there any documentation on the placeholders (because I can’t find any)?
Hi Kostas,
Yes you are right that placeholder with text are same as normal autoshapes. In order to copy the formatting of text from one placeholder to another you need to copy the desired paragraphs and their respective portions from one placeholder paragraph to another. Please visit this documentation link for your convenience to observe how to access paragraph and portions. Please visit this link for your convenience to see how to copy the paragraph and portions. Please also visit this thread link and observe the code given in the attachment where by a customer has shared the scenario where he is trying to copy paragraphs.
Also, the autoshapes can be moved to desired place as per your convenience using X and Y properties of ShapeEx and unfortunately there is no mechanism available to identify if that if the added text inside any particular shape has reached a level where it is overlapping other shapes. You may need to devise your own logic in this regard.
Please share if I may help you further in this regard.
Many Thanks,
Thanks!
I’ve figured things out now.
slide.Shapes.AddPictureFrame(ShapeTypeEx.Ellipse, float.NaN, float.NaN, float.NaN, float.NaN, null);
…how does aspose/office know which placeholder to use for getting the coordinates for the new shape?
2) Why don’t the styles of the layout (font, colors, etc) get applied automatically (just like the shape coordinates do) for each shape and I have to set them by code?
In PowerPoint, whenever you change the master slide, all the styling gets updated.
I have the impression that setting the styling by code prevents PowerPoint from setting it automatically when the user changes the master slide.
That is a problem for me.
I think I have the answers now:
Hi Kostas,
Where can I find an example which is usable with the current version of the library - the float.NaNs are not accepted for e.g. AddAutoShape anymore!
Hi Kostas,
Still have the same question as QBKleidersack, how do I add for instance a table to a table placeholder? The example from 2013 doesn’t work now with System.ArgumentException: ‘Value of x paramenter must be defined (not a float.NaN).’
@motionqiwi,
Welcome to our community! Please describe your issue in a new forum topic and share the code example throwing ArgumentException.