Free Support Forum - aspose.com

Text Find/Replace

What I’m interested in doing is a “find/replace” in all MS Office file types…word, powerpoint, excel…etc. Can this also work on outlook emails…e.g. .msg and .pst files?

I downloaded your “slides” java examples but there are a TON of them and couldn’t find a good “find/replace” example. After reading the Features Overview I think i’m looking for something along the lines of the “Text Scanning” functionality? Can you point me in the right direction to a good example, if there is one?

Thank you!

@ruberked,
Aspose provides rich features set including text find and replace in its different products. Following is the detail for each product:

Aspose.Words
Review the following article where a number of examples are given to find and replace text.
Find and Replace

Aspose.Slides
Regarding the sample code for Aspose.Slides, please try the following sample code:

Presentation presentation = new Presentation("samplepptx.pptx");
presentation.joinPortionsWithSameFormatting();
String strToReplace = "Done";
ITextFrame[] tb = SlideUtil.getAllTextFrames(presentation, true);
String find = "sample";
String strToFind= "(?i)\\b"+find+"\\b";
for (int i = 0; i < tb.length; i++)
{
	for (IParagraph ipParagraph : tb[i].getParagraphs())
	{
		for (IPortion iPortion : ipParagraph.getPortions())
		{
			if(iPortion.getText().toLowerCase().contains(find.toLowerCase()))
			{
				iPortion.setText(iPortion.getText().replaceAll(strToFind, strToReplace));
				System.out.println("replaced");
			}
		}
	}
}
presentation.save("Output.pptx",SaveFormat.Pptx);

Aspose.Cells
You can search the text and then replace using the following sample codes:
Find and replace in spreadsheet

You may also try following articles where number of techniques are given for searching text which can be replaced later using putValue() function.
Find or Search Data

Aspose.Email
Find and search text requires little different mechanism for messages and PST files. For example, the simplest code to find and replace text in the message body is given below:

MailMessage m = MailMessage.Load("GenerateMSGAspose.msg");

bool ifcontain = m.HtmlBody.Contains("[@@<span class=\"SpellE\">FullName</span>@@]");
m.HtmlBody = m.HtmlBody.Replace("[@@<span class=\"SpellE\">FullName</span>@@]", "Adnan Ahmad");
m.BodyEncoding = Encoding.ASCII;
                
m.Save("tested.msg", SaveOptions.DefaultMsg);

As messages and PST files are not simple documents, so you need to parse the messages and PST files and then find and replace text in different headers and properties. For this please visit the following articles where processing with messages and Outlook files is given in detail:
Working with MIME messages
Working with Outlook items
Working with Outlook storage files

You may try the sample codes in the above-mentioned articles and feel free to write us back if you have any query or issue while working with them. We will provide you assistance at the earliest.