Upload
Maximum file size: 1 MB. Files accepted: doc, docx, txt, rtf.
Click here to browse files.fileerrors
Convert to
Source file:
filename
Search Text:
- Demo
- Java
- C# source
This demo shows you how to search text in a Word document and highlight the text matched.
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.documents.TextSelection;
import java.awt.*;
public class FindHighlightDemo {
public void findHeighlight(String docFile, String findText, String resultFilePath){
Document doc = new Document();
doc.loadFromFile(docFile);
TextSelection[] textSelections = doc.findAllString(findText, false, true);
if(textSelections!=null){
for (TextSelection selection : textSelections) {
selection.getAsOneRange().getCharacterFormat().setHighlightColor(Color.YELLOW);
}
}
doc.saveToFile(resultFilePath, FileFormat.Docx);
}
}
No Matter How Big or Small Your Project is,
Any technical question related to our product, contact us at support@e-iceblue.com.
Any question related to the purchase of product, contact us at sales@e-iceblue.com.
If you don't find the function you want, please request a free demo from us.
