Код: Выделить всё
private void createProgressShape(Map map, Workbook workbook, Sheet sheet) {
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
DataFormat percent = workbook.createDataFormat();
cellStyle.setDataFormat(percent.getFormat("0.00%"));
List list = new ArrayList();
for (Integer rowNum : map.keySet()) {
Row row = sheet.getRow(rowNum);
Cell cell = row.getCell(1);
cell.setCellValue(map.get(rowNum));
cell.setCellStyle(cellStyle);
list.add(rowNum);
}
List segmentEndpoints = getSegmentEndpoints(list);
CellRangeAddress cra[] = {
new CellRangeAddress(segmentEndpoints.get(0), segmentEndpoints.get(1), 1, 1),
new CellRangeAddress(segmentEndpoints.get(2), segmentEndpoints.get(3), 1, 1)
};
XSSFColor color = new XSSFColor(new byte[]{(byte) 0xFF, 0x00, 0x00, (byte) 0xFF});
SheetConditionalFormatting cf = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule cfRule = cf.createConditionalFormattingRule(color);
cf.addConditionalFormatting(cra, cfRule);
DataBarFormatting format = cfRule.getDataBarFormatting();
format.getMinThreshold().setRangeType(ConditionalFormattingThreshold.RangeType.PERCENT);
format.getMinThreshold().setValue(0d);
format.getMaxThreshold().setRangeType(ConditionalFormattingThreshold.RangeType.PERCENT);
format.getMaxThreshold().setValue(100d);
}
[img]https://i.sstatic.net /FmIG2yVo.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/790 ... bar-format