2013-05-09 70 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();