Free Support Forum - aspose.com

Aspose.PowerPoint not reading the file correctly

I wrote code that goes through word and Powerpoint documents and finds certain flags (example would be <&gtWink and changes the value to a value set by my .net application.

The problem is that, for example, the <> flag is changed 3 out of 8 times in the document, rather than all 8 occurances. This happens for multiple flags (there are about 25 in all) and we are not sure why.

I am writing the code in C# and using both Aspose.Word and Aspose.PowerPoint. The code is below.


try

{

IEnumerator selectedFiles = CreateDocs.CheckedItems.GetEnumerator();

while(selectedFiles.MoveNext())

{

if (selectedFiles.Current.ToString().EndsWith(".doc") | selectedFiles.Current.ToString().EndsWith(".dot") )

{

Aspose.Word.License license = new Aspose.Word.License();

license.SetLicense(“Aspose.Word.lic”);

//Word word = new Word();

Document doc = new Document(INPUTPATH + selectedFiles.Current);

//get all fields from document

string[] fieldsArray = doc.MailMerge.GetFieldNames();

foreach (string strField in fieldsArray)

{

//need to match column in datatable to field in document

if (dv.Table.Columns.Contains(strField))

{

doc.MailMerge.MappedDataFields.Add(strField,dv.Table.Columns[strField].ColumnName);

}

}

doc.MailMerge.Execute(dv);

doc.MailMerge.Execute(dv);

doc.Save(OUTPUTPATH + selectedFiles.Current.ToString().Remove(selectedFiles.Current.ToString().Length - 3,3) + “doc”);

}

if (selectedFiles.Current.ToString().EndsWith(".ppt"))

{

Presentation pres = new Presentation(INPUTPATH + selectedFiles.Current);

for(int i = 0; i < pres.Slides.Count; i++)

{

Slide slide = pres.SlidesIdea;

for(int j = 0; j < slide.Shapes.Count; j++)

{

Shape shape = slide.Shapes[j];

if (shape is TextFrame)

{

foreach(Paragraph para in ((TextFrame)shape).Paragraphs)

{

foreach(Portion port in para.Portions)

{

// Regex reg = new Regex("<<((.|\n)?)>>", RegexOptions.IgnoreCase);

Regex reg = new Regex("<<((.|\n))>>", RegexOptions.IgnoreCase);

foreach(Match objMatch in reg.Matches(port.Text))

{

string pptField = objMatch.ToString().Substring(2,objMatch.Length-4);

if(dv.Table.Columns.Contains(pptField))

{

string newPort = port.Text.Replace(objMatch.ToString(),dr[pptField].ToString());

port.Text = newPort;

}

}

}

}

}

}

for(int j = 0; j < slide.Placeholders.Count; j++)

{

Placeholder holder = slide.Placeholders[j];

if (holder is TextHolder)

{

foreach(Paragraph para in ((TextHolder)holder).Paragraphs)

{

foreach(Portion port in para.Portions)

{

Regex reg = new Regex("<<((.|\n)*)>>", RegexOptions.IgnoreCase);

foreach(Match objMatch in reg.Matches(port.Text))

{

string pptField = objMatch.ToString().Substring(2,objMatch.Length-4);

if(dv.Table.Columns.Contains(pptField))

{

string newPort = port.Text.Replace(objMatch.ToString(),dr[pptField].ToString());

port.Text = newPort;

}

}

}

}

}

}

}

pres.Write(OUTPUTPATH + selectedFiles.Current);

}



Thanks for any help.

If <> text has formatting inside (or MS PowerPoint thinks it has formatting)
then text can be splitted to several portions. So you should check .Text property
to find text and parse all Portions to replace it.

Forgive me if that seemed a bit vague, but i am having a problem understanding the meaning of what you just told me.

Does this mean i have to write some sort of algorithm that will peice together many sequential portions in order to see if i can get <> somehow out of sequential portions?

If so, this seems a bit odd and is Aspose looking to create stronger functionality of a search and replace in powerpoint?

Thanks,
Sean Mahoney

Yes, you understood right. You should write special algorithm for that.
Why? That is proprietary format of text in MS PowerPoint (and probably MS Office).

For example you wrote simple text:
<<Example 1>>
MS PowerPoint create one portion in this case.

After that you changed formatting of this text:
<<Example 1>>
Now Paragraph has 3 portions: “<<Example”, " 1", ">>“

If you delete " 1” paragraph will contain <> text
but in 2 portions: “<<Example” and “>>”. Sometimes MS PowerPoint
merge it but only sometimes.

We are planning to add new functionality for work with text
but that is not a high priority task yet.