2013-05-09 49 views
3

:) 最后经过研究,我发现了解决我的问题,这是不能还纳XLS - 条件格式 - Java的POI例

我想使用条件格式,以显示与黄色的线如果列B和C到同一行不具有相同的值。 这是我不使用它只是为了帮我undrstund

For i = 3 To fin Step 1 
     Range("C" & i).Select 
     Selection.FormatConditions.Delete 
     Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _ 
      Formula1:="=B" & i 
     Selection.FormatConditions(1).Interior.ColorIndex = 6 

这是我的java了Methode。它是这样的,但

FileInputStream file = new FileInputStream(new File("D://DEQ//"+selectitem.getRefDeq()+"//Comparatif.xls"));   
     HSSFWorkbook workbook1 = new HSSFWorkbook(file); 
     HSSFSheet sheet1 = workbook1.getSheet("page1"); 
       HSSFSheetConditionalFormatting cf =sheet1.getSheetConditionalFormatting(); 
     HSSFConditionalFormattingRule cfrole=cf.createConditionalFormattingRule(org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator.NOT_EQUAL, "120"); 

     HSSFPatternFormatting fill_pattern = cfrole.createPatternFormatting(); 
     fill_pattern.setFillBackgroundColor(IndexedColors.YELLOW.index); 

     CellRangeAddress[] my_data_range = {CellRangeAddress.valueOf("B17:B26")}; 
     cf.addConditionalFormatting(my_data_range,cfrole); 
FileOutputStream out = new FileOutputStream(new File("D://DEQ//"+selectitem.getRefDeq()+"//Comparatif.xls")); 
     workbook1.write(out); 
     out.close(); 

这个例子很好地工作它显示我对VBA马可孛黄色的线。但正如您已经看到的,我的值是a = 120,并且显示的颜色是黄色。问题是,我认为这些数值不是我网页中的数字格式..这不是问题

我真正的问题是我必须与之比较的价值,我不知道我是如何表达的即每个框B和C的同一行。 我把这里的单一值= 120只为试验

我应该做的..在价值comprarer 如何预先感谢您:)

回答

1

你可以得到细胞财产对象,并且如果内容是数字,则该值将是数字。

+0

认为你@philip .I'm现在得到一个结果,它工作正常,但因为我不是一个无法发布我的雁有10个repution hhhhh :) – salvador 2013-05-10 07:36:43

3

Finaly这是我的解决方案..think你@Philip

FileInputStream file = new FileInputStream(new File("D://DEQ//"+selectitem.getRefDeq()+"//Comparatif.xls"));   
      HSSFWorkbook workbook1 = new HSSFWorkbook(file); 
      HSSFSheet sheet1 = workbook1.getSheet("Comparatif"); 
      //Get first sheet from the workbook 

      HSSFSheetConditionalFormatting cf =sheet1.getSheetConditionalFormatting(); 
      int i; 
      i=17; 
      for(;i<=ligne;i++){ 
      HSSFConditionalFormattingRule cfrole=cf.createConditionalFormattingRule(ComparisonOperator.NOT_EQUAL,"$C$"+i); 
      HSSFPatternFormatting fill_pattern = cfrole.createPatternFormatting(); 
      fill_pattern.setFillBackgroundColor(IndexedColors.YELLOW.index); 
      CellRangeAddress[] my_data_range = {CellRangeAddress.valueOf("B"+i+":B"+i)}; 
      cf.addConditionalFormatting(my_data_range,cfrole); 
      } 
      for(i=17;i<=ligne;i++){ 
       HSSFConditionalFormattingRule cfrole=cf.createConditionalFormattingRule(ComparisonOperator.NOT_EQUAL,"$B$"+i); 
       HSSFPatternFormatting fill_pattern = cfrole.createPatternFormatting(); 
       fill_pattern.setFillBackgroundColor(IndexedColors.YELLOW.index); 
       CellRangeAddress[] my_data_range = {CellRangeAddress.valueOf("C"+i+":C"+i)}; 
       cf.addConditionalFormatting(my_data_range,cfrole); 
       } 
    FileOutputStream out = new FileOutputStream(new File("D://DEQ//"+selectitem.getRefDeq()+"//Comparatif.xls")); 
      workbook1.write(out); 
      out.close();