With Spire.XLS for java, we could find and replace data in Excel easily. This article will demonstrate how to find and highlight data in Excel.
Firstly, view the sample document:
import com.spire.xls.*; import java.awt.*; public class FindandHighlight { public static void main(String[] args) { //Load the sample document Workbook workbook = new Workbook(); workbook.loadFromFile("Sample.xlsx"); //Get the second worksheet Worksheet worksheet = workbook.getWorksheets().get(1); //Find the text string "Mexico" CellRange[] ranges = worksheet.findAllString("Mexico", true, true); for (CellRange range : ranges) { //Set the color to highlight the text range.getCellStyle().setColor(Color.yellow); } //Save the document to file workbook.saveToFile("output/FindandHighlight.xlsx", ExcelVersion.Version2010); } }
Effective screenshot after find and highlight the data in Excel: