Java Apache-POI彩色单元格及其公式

Java Apache-POI彩色单元格及其公式,java,excel,apache-poi,Java,Excel,Apache Poi,我想用java中的ApachePOI创建一个excel,我必须在单元格中插入一个公式:A3=B3+C3 是否可以在A3中插入另一个公式,在其值大于0时为单元格着色 我使用ApachePOI2.5.1,您需要一个 从本文件中: // Define a Conditional Formatting rule, which triggers formatting // when cell's value is greater or equal than 100.0 and // applies

我想用java中的ApachePOI创建一个excel,我必须在单元格中插入一个公式:A3=B3+C3

是否可以在A3中插入另一个公式,在其值大于0时为单元格着色

我使用ApachePOI2.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创建一个红色背景的单元格。这几乎就是你想要的:-)