I have a java code which compares 2 excel sheets and generates results in a new excel sheet. I have to modify the code in a way that where ever the value of the cell is "Cell Data matches" the cell color should be in red color. Please help me out doing this. TIA
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
System.out.print("Enter Sheet1 path: ");
String name1 = in.nextLine();
System.out.print("Enter Sheet2 path: ");
String name2 = in.nextLine();
FileInputStream file1 = new FileInputStream(new File(name1));
FileInputStream file2 = new FileInputStream(new File(name2));
Path p = Paths.get(name1);
String filenameTOExempt = p.getFileName().toString();
String fileAbsolutePath = p.toAbsolutePath().toString();
String filePath = fileAbsolutePath.replace(filenameTOExempt, "");
// Creating an Empty WorkBook
XSSFWorkbook resultSheet = new XSSFWorkbook();
// Create a blank sheet
XSSFSheet sheet = resultSheet.createSheet("Comparison Results");
// This data needs to be written (Object[])
Map<String, Object[]> data = new TreeMap<String, Object[]>();
int n = 1;
try (Workbook wb1 = WorkbookFactory.create(file1)) {
try (Workbook wb2 = WorkbookFactory.create(file2)) {
for (String d : ExcelComparator.compare(wb1, wb2)) {
// Finding the index of : in order to seperate the Result from d
String num = Integer.toString(n);
int iend = d.indexOf(":");
String res = d.substring(0, iend);
res = res.trim();
String data1 = StringUtils.substringBetween(d, "[", "]");
d = d.replace("["+data1+"]", "");
String data2 = StringUtils.substringBetween(d, "[", "]");
data.put(num, new Object[]{ data1, data2, res });
n++;
in.close();
file1.close();
file2.close();
}
}
}
where ever the cell has the value "Cell Data Matches" those cells should be in red.