我必須使用簡單的公式驗證單元格,如果無效,請將單元格顏色更改爲黃色或紅色,這並不重要。使用java更改excel單元格顏色
到目前爲止,我已經看到了,並嘗試這個辦法:
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
// formula = =SUMA(L13+M13+N13+O13)
//=SUMA(M4+N4+O4+P4+L:L
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "4");
PatternFormatting fill2 = rule2.createPatternFormatting();
fill2.setFillBackgroundColor(IndexedColors.GREEN.index);
fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
CellRangeAddress[] regions = { CellRangeAddress.valueOf("L2:L5")};
sheetCF.addConditionalFormatting(regions, rule2);
}
這改變了我的顏色,如果值是四,我知道,但
如何申請和的公式的:
我需要在列L,M2 + N2 + O2 + P2和M3 + N3 + O3 + P3等的總和......的所有行驗證
僅供參考,我得到的值從DB和值都喜歡與小數的圖片,但我讓他們在Java作爲INT這樣的:
while((j < fallas) && rset.next()){
row = sheet.createRow(j+1);
row.createCell(0).setCellValue((rset.getBigDecimal(1)).toString());
row.createCell(1).setCellValue(rset.getString(2));
row.createCell(2).setCellValue(rset.getString(3));
row.createCell(3).setCellValue(rset.getString(4));
row.createCell(4).setCellValue(rset.getString(5));
row.createCell(5).setCellValue(rset.getString(6));
row.createCell(6).setCellValue(rset.getString(7));
row.createCell(7).setCellValue((rset.getBigDecimal(8)).toString());
row.createCell(8).setCellValue((rset.getBigDecimal(9)).toString());
row.createCell(9).setCellValue((rset.getBigDecimal(10)).toString());
row.createCell(10).setCellValue(rset.getString(11));
//row.createCell(11).setCellFormula("SUMA(L13+M13+N13+O13)");
row.createCell(11).setCellValue(String.valueOf((rset.getBigDecimal(12)).toString()));
row.createCell(12).setCellValue(String.valueOf((rset.getBigDecimal(13)).toString()));
row.createCell(13).setCellValue(String.valueOf((rset.getBigDecimal(14)).toString()));
row.createCell(14).setCellValue(String.valueOf((rset.getBigDecimal(15)).toString()));
row.createCell(15).setCellValue(String.valueOf((rset.getBigDecimal(16)).toString()));
row.createCell(16).setCellValue((rset.getString(17)));
row.createCell(17).setCellValue((rset.getString(18)));
row.createCell(18).setCellValue(rset.getString(19));
row.createCell(19).setCellValue(rset.getString(20));
row.createCell(20).setCellValue("-");
row.createCell(21).setCellValue(new java.sql.Date(rset.getDate(22).getTime()).toString());
row.createCell(22).setCellValue((rset.getBigDecimal(23)).toString());
row.createCell(23).setCellValue("-");
row.createCell(24).setCellValue("-");
row.createCell(25).setCellValue("-");
row.createCell(26).setCellValue("-");
row.createCell(27).setCellValue((rset.getBigDecimal(28)).toString());
row.createCell(28).setCellValue((rset.getBigDecimal(29)).toString());
row.createCell(29).setCellValue(rset.getString(30));
row.createCell(30).setCellValue(rset.getString(31));
row.createCell(31).setCellValue(rset.getString(32));
L,M,N,O,P是createCell(11),12,13,14等
如果我只是把公式放在「createConditionalFormattingRule」它不會做任何事情:(請幫助我!
感謝@JoshC! – jompi