我想用java中的Apache POI创建一个excel,我必须在一个单元格中插入一个公式:A3=B3+C3。
如果他的值> 0,是否可以在 A3 中插入另一个为单元格着色的公式?
我使用 Apache POI 2.5.1
我想用java中的Apache POI创建一个excel,我必须在一个单元格中插入一个公式:A3=B3+C3。
如果他的值> 0,是否可以在 A3 中插入另一个为单元格着色的公式?
我使用 Apache POI 2.5.1
您将需要条件格式。
从这个文件:
// Define a Conditional Formatting rule, which triggers formatting
// when cell's value is greater or equal than 100.0 and
// applies patternFormatting defined below.
HSSFConditionalFormattingRule rule = sheet.createConditionalFormattingRule(
ComparisonOperator.GE,
"100.0", // 1st formula
null // 2nd formula is not used for comparison operator GE
);
// Create pattern with red background
HSSFPatternFormatting patternFmt = rule.cretePatternFormatting();
patternFormatting.setFillBackgroundColor(HSSFColor.RED.index);
// Define a region containing first column
Region [] regions =
{
new Region(1,(short)1,-1,(short)1)
};
// Apply Conditional Formatting rule defined above to the regions
sheet.addConditionalFormatting(regions, rule);
它为值> = 100创建一个具有红色背景的单元格。这几乎是您想要的:-)