Bug反馈 代码生成的数据条wps打开异常
如图,左侧用excel打开数据条100%时满格显示正常,右侧wps打开,100%颜色填充未满。同一个文件。
//相关代码 处理百分比
private void cell4(Sheet sheet,int cellInt,CellStyle percentStyle) {
// 创建条件格式规则
SheetConditionalFormatting formatting = sheet.getSheetConditionalFormatting();
XSSFColor color = new XSSFColor(IndexedColors.ROYAL_BLUE, new DefaultIndexedColorMap());
ConditionalFormattingRule rule = formatting.createConditionalFormattingRule(color);
XSSFDataBarFormatting dataBarFormatting = (XSSFDataBarFormatting) rule.getDataBarFormatting();
dataBarFormatting.getMinThreshold().setRangeType(ConditionalFormattingThreshold.RangeType.NUMBER);
dataBarFormatting.getMaxThreshold().setRangeType(ConditionalFormattingThreshold.RangeType.NUMBER);
dataBarFormatting.getMinThreshold().setValue(0.0);
dataBarFormatting.getMaxThreshold().setValue(1.0);
dataBarFormatting.setWidthMin(0);
dataBarFormatting.setWidthMax(100);
try{
Field _databar = XSSFDataBarFormatting.class.getDeclaredField("_databar");
_databar.setAccessible(true);
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataBar ctDataBar =
(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataBar)_databar.get(dataBarFormatting);
ctDataBar.setMinLength(0);
ctDataBar.setMaxLength(100);
} catch (Exception e){
}
String addr;
if(cellInt == 4){
addr = "E3:E" + (sheet.getPhysicalNumberOfRows());
}else {
addr = "C3:C" + (sheet.getPhysicalNumberOfRows() + 1);
}
CellRangeAddress[] range = {
CellRangeAddress.valueOf(addr)
};
formatting.addConditionalFormatting(range,rule);
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
Row r = sheet.getRow(i);
if(r == null){
continue;
}
Cell cell = r.getCell(cellInt);
if(cell.getCellType() == CellType.NUMERIC){
cell.setCellStyle(percentStyle);
}
}
if(cellInt == 2){
sheet.getRow(sheet.getPhysicalNumberOfRows()).getCell(2).setCellStyle(percentStyle);
}
}
@金山办公
@金山办公