Create Pptx form template

Hi,


I am having one business requirement as we need to find Text & replace with custom values in pptx/ppt format.

We are using Aspose.slides 8.3.0.0 for .Net plateform.

But after replacing text with custom values ,text format getting change .We need to maintain formatting of the pptx/ppt after replacement of custom values.

We are using following code

string dataDir = Request.PhysicalApplicationPath + “\Data\”;

//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation(dataDir + “FindAndReplace.ppt”);

//Slides slides = pres.Slides;

//Accessing a slide using its slide position
int slideCount = pres.Slides.Count;
for (int i = 1; i <= pres.Slides.Count; i++)
{
Slide slide = pres.GetSlideByPosition(i);

int placeholdersCount = slide.Placeholders.Count;

for (int j = 0; j < placeholdersCount; j++)
{
//Accessing the first placeholder in the slide and typecasting it as a text holder
TextHolder th = (TextHolder)slide.Placeholders[j];
//Comparing the text in text holder to find a specific text holder. If the
//text matches then replace the text inside that text holder
th.Text = th.Text.Replace("", System.DateTime.Today.ToShortDateString());
th.Text = th.Text.Replace("", “Motorola”);
th.Text = th.Text.Replace("", “AmSouth/Harbert Plaza”);
th.Text = th.Text.Replace("", “Birmingham”);
th.Text = th.Text.Replace("", “Albama”);
th.Text = th.Text.Replace("", “35203”);
th.Text = th.Text.Replace("", “Allen Border”);
th.Text = th.Text.Replace("", System.DateTime.Today.AddDays(-10).ToShortDateString());
th.Text = th.Text.Replace("", System.DateTime.Today.AddDays(-1).ToShortDateString());
th.Text = th.Text.Replace("", “Max”);
}
}

//Writing the presentation as a PPT file
pres.Write(dataDir + “FindAndReplace out.ppt”);


But after replacing text with custom values ,text format getting change .We need to maintain formatting of the pptx/ppt after replacement of custom values.

Please find attached ppt for your reference.

Your quick response is appreciated in advance.



Hi,


Thanks for inquiring Aspose.Slides.

I have observed your requirements and shared sample code. Actually, you are setting the text on TextHolder/TextFrame level, the text formatting gets reset. In order to retain the text formatting you need to replace the text on lowest level i.e. Portion level. Please use the attached sample code on your end to serve the purpose.

public static void ReplaceText()
{
string dataDir = @“C:\Presentations”;

//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation(dataDir + “FindAndReplace.ppt”);

//Slides slides = pres.Slides;

//Accessing a slide using its slide position
int slideCount = pres.Slides.Count;
Paragraph para = null;
Portion portion = null;

for (int i = 1; i <= pres.Slides.Count; i++)
{
Slide slide = pres.GetSlideByPosition(i);

int placeholdersCount = slide.Placeholders.Count;

for (int j = 0; j < placeholdersCount; j++)
{
//Accessing the first placeholder in the slide and typecasting it as a text holder
TextHolder th = (TextHolder)slide.Placeholders[j];

//Comparing the text in text holder to find a specific text holder. If the
//text matches then replace the text inside that text holder

for (int k = 0; k < th.Paragraphs.Count; k++)
{
para = th.Paragraphs[k];
String st1,st2;

for (int x = 0; x < para.Portions.Count; x++)
{
portion = para.Portions[x];
portion.Text=portion.Text.Replace("", System.DateTime.Today.ToShortDateString());
portion.Text = portion.Text.Replace("", “Motorola”);
portion.Text = portion.Text.Replace("", “AmSouth/Harbert Plaza”);
portion.Text = portion.Text.Replace("", “Birmingham”);
portion.Text = portion.Text.Replace("", “Albama”);
portion.Text = portion.Text.Replace("", “35203”);
portion.Text = portion.Text.Replace("", “Allen Border”);
portion.Text = portion.Text.Replace("", System.DateTime.Today.AddDays(-10).ToShortDateString());
portion.Text = portion.Text.Replace("", System.DateTime.Today.AddDays(-1).ToShortDateString());
portion.Text = portion.Text.Replace("", “Max”);
}
}
}
}

//Writing the presentation as a PPT file
pres.Write(dataDir + “FindAndReplace out.ppt”);

}

Please share, if I may help you further in this regard.

Many Thanks,

Hi Mudassir ,



Thanks a lot for your quick response.

I have tried above code at mine side ,but result is not reflected as expected.

Please find attached ppt for your ref.

As of now we are evaluating above tool as per business requirement.

So now we are using Evaluation copy of Aspose.Slides.

We would like to demo POC to client above mentioned business requirement,based on POC result client will go for license copy of the same.

Can you please help me out for the same?

Hi,


Thanks for your feedback. I have observed the generated presentation shared by you and it is due to limitation of evaluation version that you are using. For your POC, I suggest you to please try using our 30 days trial license on your end for making any purchase decision. Please visit Get Temporary License page for your kind reference in this regard.

Please share, if I may help you further in this regard.

Many Thanks,

Hi Mudassir,


Thanks a lot for your quick response.
We appreciate your help.