Anonymous
Процент вывода пои отображается в формате индикатора выполнения.
Сообщение
Anonymous » 10 окт 2024, 10:57
Я столкнулся с проблемой при экспорте данных в виде индикатора выполнения с помощью poi: индикатор выполнения будет отображаться, если значение равно 0%. Мне нужна ваша помощь, чтобы решить эту проблему, спасибо. Вот мой исходный код.
Код: Выделить всё
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
1728547024
Anonymous
Я столкнулся с проблемой при экспорте данных в виде индикатора выполнения с помощью poi: индикатор выполнения будет отображаться, если значение равно 0%. Мне нужна ваша помощь, чтобы решить эту проблему, спасибо. Вот мой исходный код. [code]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); } [/code] Ниже показан экспортированный рендеринг. [img]https://i.sstatic.net /FmIG2yVo.png[/img] Подробнее здесь: [url]https://stackoverflow.com/questions/79073194/the-poi-output-percentage-is-in-progress-bar-format[/url]