We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

FindAndHighlight In PDF- Powerpoint and Excel

Hi,

I already found in your documentation a way to Find and Highlight words and strings using Regular Expressions in word documents. The problem we are having right now is that we would like to be able to do the same thing with Excel, PowerPoint and PDF documents, In the worst case we could convert Powerpoints and Excel to PDF documents and use PDF documents only.

The cool thing about your example in Word documents is that it uses Regular Expression and it uses the match as a replacement instead of having us specify the replacement string, which means it keeps previous text formating.

I found this example in your documentation https://docs.aspose.com/pdf/java/replace-text/ and I tried it, but in C#, and the result is just not what I was waiting for. Sometimes the replacement string is simply put above existing text, the background color is not properly positioned, like clearly not under the specified replacement string etc. Here is the code I tried, and I attached the PDF file:

private static void ReplaceAndHighlightInPdf()
{
PdfContentEditor contentEditor = new PdfContentEditor();
//bind input PDF file
contentEditor.BindPdf(dataDir + “pdfTestFile.pdf”);
contentEditor.ReplaceTextStrategy.IsRegularExpressionUsed = false;
contentEditor.ReplaceTextStrategy.ReplaceScope = ReplaceTextStrategy.Scope.REPLACE_ALL;
//create object of TextProperties class
PdfContentEditor.TextProperties textProperties = new PdfContentEditor.TextProperties();
textProperties.BackgroundColor = Color.Yellow;
//replace old sting with the same text and new text properties
contentEditor.ReplaceText(“your document”, “your document”, textProperties);
//save the output PDF file
contentEditor.Save(“output.pdf”);
contentEditor.Close();
}

EDIT: It seems my PDF document was the problem concerning the background color not being applied at the proper position. So the remaining question is how could I achieve this like you did in the word example where you can use the found match as the replacement string in order to keep formating, and uppercase characters etc…?

Thanks for any help.

Hi,


I am a representative of Aspose.Cells team and will assist regarding find and replace options in Excel spreadsheet’s cells. See some sample Examples below for your reference:

1)
Workbook workbook = new Workbook(@“e:\test\Book1.xls”);
WorksheetCollection worksheets = workbook.Worksheets;
string stringtofind = “Test”;
string stringtoreplace = “Rock”;
for (int i = 0; i < worksheets.Count; i++)
{

Worksheet worksheet = workbook.Worksheets[i];
Cells cells = worksheet.Cells;
Cell cell;
Cell prevcell = null;

do
{
cell = cells.FindStringContains(stringtofind, prevcell);
if (cell == null)
break;
string val = cell.StringValue.Replace(stringtofind, stringtoreplace);
cell.PutValue(val);
prevcell = cell;

} while (cell != null);

}
workbook.Save(“e:\test\outBook1.xls”);
workbook.Save(“e:\test\outBookPdf.pdf”, SaveFormat.Pdf);


2)
Workbook wb = new Workbook(“e:\test\Test.xls”);
ReplaceOptions replace = new ReplaceOptions();
replace.CaseSensitive = false;
replace.MatchEntireCellContents = false;
//Replace all occurrings in the whole workbook.
wb.Replace(“officialName”, “AwesomeAgency”, replace);
//Note: We have also Worksheet.Replace method to perform the task at worksheet level only
wb.Save(“e:\test\outTest.xls”);
wb.Save(“e:\test\outTestPdf.pdf”, SaveFormat.Pdf);

Also, to format the cells or data in Excel worksheets further, see the documents:
http://www.aspose.com/docs/display/cellsnet/Dealing+with+Font+Settings
Colors and Background Patterns


Thank you.

Hi and thanks for your quick answer!


The only part I’m having trouble with right now is the Highlighting part. I do not think it is currently possible to Highlight search results in Excel nor Powerpoint documents so I figured I will have to convert those documents to PDF in order to achieve that.

Thanks a lot again.

Hi,

Regarding Aspose.Cells and Ms-Excel, I will add that

Once, you are done finding the cells with your searched items, you can them fill them with background color e.g.

Please see the code below how to fill the cell with some color e.g red, green etc.

C#


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.Worksheets[0];


Cell cell = worksheet.Cells[“C3”];


Style style = cell.GetStyle();

style.Pattern = BackgroundType.Solid;

style.ForegroundColor = Color.Green;

cell.SetStyle(style);



workbook.Save(@“F:\Shak-Data-RW\Downloads\output.xlsx”);

Screenshot:


Hi,


I am representing Aspose.Slides.

I like to share that the support for highlighting some particular portion of text inside any shape of PowerPoint is not even available in MS PowerPoint. What you can do is to keep the intended highlighted text in a separate shape and then set the shape fore color. It will serve as a work around for highlighting the text. However, I have created an issue with ID SLIDESNET-33345 in our issue tracking system as new feature request so as when MS will incorporate this feature, we will also try to implement the same in Aspose.Slides. Please also read Article [link 1](http://office.microsoft.com/en-us/powerpoint-help/what-happened-to-the-text-highlight-option-HA010199730.aspx) and link 2 for your further information. I have also shared the workaround method code as well that you may use to highlight the text for the time being.

Presentation pres = new Presentation();

Slide slide = pres.GetSlideByPosition(1);

Aspose.Slides.Rectangle bitName = slide.Shapes.AddRectangle(1000, 1000, 1000, 500);

TextFrame bitNameTF = bitName.AddTextFrame(“Some Text”);

bitNameTF.MarginTop=0;

bitNameTF.MarginLeft=2;

bitNameTF.MarginBottom=12.0;

bitNameTF.LineFormat.ShowLines=true;

Aspose.Slides.Paragraph bitPara2 = bitNameTF.Paragraphs[0];

bitPara2.Alignment=TextAlignment.Right;

Portion bitPort2 = bitNameTF.Paragraphs[0].Portions[0];

bitPort2.FontColor=Color.Blue ;

bitPort2.FontHeight=15;

bitNameTF.FillFormat.Type=FillType.Solid;

bitNameTF.FillFormat.ForeColor=Color.Yellow ;


pres.Write(“D:\Aspose Data\TextAlign.ppt”);


Many Thanks,

Hello
Louis-Philippe,


Thanks for contacting support.

I am a representative from Aspose.Pdf team. Please try using Document class present under Aspose.Pdf namespace to search and update text inside PDF documents. Please visit the following links for further information on Replace Text Based on a Regular Expression

If you notice any problem or you have any further query, please feel free to contact.


Thanks to all of you for your quick replies, I think that with those I should be able to build my solution.


I believe I will convert Powerpoint and Excel document to PDF and perform the search and highlight on the resulting PDF documents as it gives a better result in my opinion. As mentioned before, you can only fill a cell in excel instead of Highlighting specific words and you can’t highlight in powerpoint so I think this is the best solution for now.

Thanks again!