POI Excel 冷冻线
冷冻线
Sheet.createFreezePane
data bar and color scale
SheetConditionalFormatting scf = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule cfr = getConditionalFormattingRule( scf );
CellRangeAddress cra[] = {new CellRangeAddress(ROW_ROOT_INDEX, ROW_ROOT_INDEX + rows.length,
COLUMN_ROOT_INDEX, COLUMN_ROOT_INDEX + columns.length * className.length )};
scf.addConditionalFormatting(cra, cfr);
private ConditionalFormattingRule getConditionalFormattingRule( SheetConditionalFormatting scf ) {
ConditionalFormattingRule cfr = scf.createConditionalFormattingRule("");
try {
Method m = cfr.getClass().getDeclaredMethod("getCTCfRule");
m.setAccessible(true);
CTCfRule cfRule = (CTCfRule) m.invoke(cfr);
m.setAccessible(false);
cfRule.removeFormula(0);
// cfRule.setType(STCfType.DATA_BAR);
// CTDataBar databar = cfRule.addNewDataBar();
// CTCfvo vfoMin = databar.addNewCfvo();
// vfoMin.setType(STCfvoType.NUM);
// vfoMin.setVal("0");
// CTCfvo vfoMax = databar.addNewCfvo();
// vfoMax.setType(STCfvoType.NUM);
// vfoMax.setVal("1");
// CTColor color = databar.addNewColor();
// color.setRgb(new byte[] { (byte) 0xFF, 0x00, 0x00, (byte) 0xFF });
cfRule.setType(STCfType.COLOR_SCALE);
CTColorScale cScale = cfRule.addNewColorScale();
CTCfvo vfo = cScale.addNewCfvo();
vfo.setType(STCfvoType.NUM);
vfo.setVal("0");
vfo = cScale.addNewCfvo();
vfo.setType(STCfvoType.NUM);
vfo.setVal("0.5");
vfo = cScale.addNewCfvo();
vfo.setType(STCfvoType.NUM);
vfo.setVal("1");
CTColor color = cScale.addNewColor();
color.setRgb(new byte[]{(byte)255, (byte)99, (byte)190, (byte)123});
color = cScale.addNewColor();
color.setRgb(new byte[]{(byte)255, (byte)255, (byte)235, (byte)132});
color = cScale.addNewColor();
color.setRgb(new byte[]{(byte)255, (byte)248, (byte)105, (byte)107});
} catch (Exception e) {
e.printStackTrace();
cfr = null;
}
return cfr;
}