HSSFWorkbook outWB = new HSSFWorkbook();
HSSFSheet outSheet = outWB.createSheet("Sheet1");    
     HSSFRow outFstRow = outSheet.createRow((short)0);
     HSSFRow outRow = outSheet.createRow((short)1);
    
     HSSFCellStyle cellStyle = outWB.createCellStyle();
     HSSFCellStyle cellStyleclor = outWB.createCellStyle();
    
     Workbook workBook = new Workbook();
     HSSFDataFormat hSSFDataFormat = new HSSFDataFormat(workBook);
     cellStyleclor.setFillForegroundColor(HSSFColor.RED.index);
     cellStyleclor.setFillBackgroundColor(HSSFColor.BLUE.index);
     cellStyle.setDataFormat(hSSFDataFormat.getFormat("yy-mmm-d"));        
         for(int m=0;m<columnList.size();m++){
   column =columnList.get(m)+"";
           HSSFCell outCell = outFstRow.createCell((short)m);
   outCell.setCellValue(column);
   outCell.setCellStyle(cellStyleclor);   //这段setCellValue后 单元格颜色不变
   
        }
b: for(int n=0;n<columnList.size();n++){
   cell = row.getCell((short)n);
   if(cell!=null){
      if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
    String data = cell.getStringCellValue();
    outRow.createCell((short)n).setCellValue(data);
      }else if(HSSFDateUtil.isCellDateFormatted(cell)){
    Date data =cell.getDateCellValue();
    outRow.createCell((short)n).setCellValue(data);
    outRow.createCell((short)n).setCellStyle(cellStyle);
      }else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
    double data = cell.getNumericCellValue();
    outRow.createCell((short)n).setCellValue(data); // 这段setCellValue后 单元格显示空
      }刚开始用POI 按照别人的例子写一个 结果发现 不论是设置日期格式 还是背景颜色 只要我写setCellValue 就不好用。。
我把代码写上衣部分, 大家帮看看阿 先谢谢啦

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【adong1423】截止到2008-07-09 10:34:12的历史汇总数据(不包括此帖):
    发帖的总数量:0                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:---------------------结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    参考这里 http://blog.csdn.net/zhaozhi_1983/archive/2008/04/20/2309621.aspx
      

  3.   

    回复过一次了lz参考http://topic.csdn.net/u/20080704/16/0102f610-f630-48ee-8b4f-0f70ddbfdc19.html
      

  4.   

    就是我写注释那两行不好用 麻烦大家帮看看阿.....................
    着急ING。。
      

  5.   

    颜色解决了! 就差日期格式了! 
         HSSFWorkbook outWB = new HSSFWorkbook(); 
        HSSFSheet outSheet = outWB.createSheet("Sheet1");    
        HSSFRow outFstRow = outSheet.createRow((short)0); 
        HSSFRow outRow = outSheet.createRow((short)1); 
        
        HSSFCellStyle cellStyle = outWB.createCellStyle(); 
        Workbook workBook = new Workbook(); 
        HSSFDataFormat hSSFDataFormat = new HSSFDataFormat(workBook); 
        cellStyle.setDataFormat(hSSFDataFormat.getFormat("yy-mmm-d")); 。。
        else if(HSSFDateUtil.isCellDateFormatted(cell)){ 
         Date data =cell.getDateCellValue(); 
          outRow.createCell((short)n).setCellValue(data); 
          outRow.createCell((short)n).setCellStyle(cellStyle); // 这段setCellValue后 单元格显示空
        }

    这个日期不写 就显示 2008-2-15 00:00:00 写上setCellValue 就显示空! 为什么阿? 我什么地方写错了?????????????????????????????????????????????