list中的数据为 
   1. {“数据1”,“数据2”, “数据3”}  我用这段代码生成一系列的Cell,但是发现只能生成最后一个 。
for (int j = 0; j < 3; j++) { HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell(j);

cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue((String) list.get(i));
}
然后我用下面方式就可以生成我想要的:  HSSFRow row = sheet.createRow(0);                        row.createCell(0).setCellValue(list.get(0)); row.createCell(1).setCellValue(list.get(1)); row.createCell(2).setCellValue(list.get(2));
我现在有个巨大的疑问,
当我的数据有100000个,不可以一直用下面的方法的!!
我该怎么弄!? 现在有点想换报表导出的工具了  
今晚就要做出来这功能
jasperreport,ireport,jxl,这几个哪个好学?
当然如果POI这个问题解决了就好了!

解决方案 »

  1.   

    看一下吧。。POI
    /**
     * 导出
     * @param list
     * @param sheetName
     * @param title
     * @return
     */
    public static InputStream ExportToExcel(List<VAllUser> list,String sheetName,String[] title) 
    {
    //创建一个空工作空间
      HSSFWorkbook workbook=new HSSFWorkbook();
      //创建一个表
      HSSFSheet sheet=workbook.createSheet(sheetName);
      
      HSSFRow titleRow=sheet.createRow(0);
      SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
      createTitleRow(workbook, titleRow, title);
      int rowNum=1;
      int col=0;
      for(int i=0;i<list.size();i++)
      {
      HSSFRow row=sheet.createRow(rowNum++);
      int colNum=0;
      VAllUser user=list.get(i);
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getDmName());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getOrgName());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserName());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserEmail());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserGender());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserBorn());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserCardid());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserTel());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserAddress());
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        if(user.getUserValiddate()!=null)
       {
        row.createCell(col).setCellValue(sdf.format(user.getUserValiddate()));
       }else
       {
       row.createCell(col).setCellValue(" "); 
       }
        col=colNum++;
        row.createCell(col).setCellType(HSSFCell.CELL_TYPE_STRING);
        row.createCell(col).setCellValue(user.getUserLang());
       
      
           }
      ByteArrayOutputStream os=new ByteArrayOutputStream();   
            try {   
             workbook.write(os);   
                   
            } catch (IOException e) {   
                e.printStackTrace();   
            }   
            byte[] bytes=os.toByteArray();   
            InputStream is=new ByteArrayInputStream(bytes);   
            return is;   
    }
    private static void createTitleRow(HSSFWorkbook workbook,HSSFRow row,String[] title)
    {
      int length=title.length;
      HSSFCellStyle style=workbook.createCellStyle();
      HSSFFont font=workbook.createFont();
      font.setColor(HSSFColor.BLUE.index);
      font.setFontHeightInPoints((short)14);
      font.setBoldweight((short)24);
      style.setFont(font);
      style.setFillBackgroundColor(HSSFColor.YELLOW.index);
      for(int i=0;i<length;i++)
      {
       HSSFCell cell=row.createCell(i);
        cell.setCellValue(title[i]);
       cell.setCellStyle(style);
      }
    }
    private static String getString(String str,int type)
    {
    System.out.println(str+"--"+type);
     if(type==0)
    {
     str=str.substring(0,str.indexOf("."));
    }
    return str;
    }
      

  2.   

    谢谢楼上 我已经找到答案 就是HSSFRow row =null;
     HSSFCell cell = null;
    for (int j = 0; j < 3; j++) {                row = sheet.createRow(0);                cell = row.createCell(j);
        
                    cell.setCellType(HSSFCell.CELL_TYPE_STRING);                cell.setCellValue((String) list.get(i));
                }