现在我的excel中有多个底色,如何用java获得单元格的底色?
能将各单元格的底色加以区别

解决方案 »

  1.   

    jxl 用过读取Excel数据
    没尝试过如何获取单元格底色
      

  2.   


    HSSFCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    HSSFCellStyle.setFillForegroundColor(color);
    这个是设置的,HSSFCellStyle.getFillBackgroundColor()获取的。
      

  3.   


       public static void main(String[] args) throws IOException {
          FileOutputStream out = new FileOutputStream("c:\\color.xls");
          HSSFWorkbook book = new HSSFWorkbook();
          HSSFSheet sheet = book.createSheet();
          
          
          for(int i = 0; i < 70; i++) {
             HSSFRow row = sheet.createRow(i);
             HSSFCell cell = row.createCell(0);
             cell.setCellValue(i);
             HSSFCellStyle style = book.createCellStyle();
             style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
             style.setFillForegroundColor((short) i);
             cell.setCellStyle(style);
          }      book.write(out);
          System.err.println("OK");
       }
    由于获取的color是short类型的,上面方法是将具体颜色和short值关联起来了。