呵呵,操作excel我觉得还是java excel api 就是jxl好使,简单又方便!
你的问题我估计可能是多线程的问题!!
因为我做过跟你一样的东东!不过我是用jxl

解决方案 »

  1.   

    是吗,但是我老板非要用这个,我当小兵的不好说什么呢,servlet是非线程安全的,这个我明白,但是如何解决呢
      

  2.   

    第一个问题可能是由于表格的格式设置有问题,不要管了,
    请问有没有知道如何控制cell格式的,譬如,设置cell的颜色什么的
      

  3.   

    难道没有知道如何用POI设定表元格式的吗,在线等待,解决立即给分
      

  4.   

    HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("new sheet");        // Create a row and put some cells in it. Rows are 0 based.
            HSSFRow row = sheet.createRow((short) 1);        // Aqua background
            HSSFCellStyle style = wb.createCellStyle();
            style.setFillBackgroundColor(HSSFCellStyle.AQUA);
            style.setFillPattern(HSSFCellStyle.BIG_SPOTS);
            HSSFCell cell = row.createCell((short) 1);
            cell.setCellValue("X");
            cell.setCellStyle(style);        // Orange "foreground", foreground being the fill foreground not the font color.
            style = wb.createCellStyle();
            style.setFillForegroundColor(HSSFCellStyle.ORANGE);
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            cell = row.createCell((short) 2);
            cell.setCellValue("X");
            cell.setCellStyle(style);        // Write the output to a file
            FileOutputStream fileOut = new FileOutputStream("workbook.xls");
            wb.write(fileOut);
            fileOut.close();
      

  5.   

    到apache的网站上面下载源程序,有使用的例子好多的,
      

  6.   

    to:teva(用正确的理论引导人) 太感谢了
    再请教一个问题,我在导出时,当行数很多时,出现:不能打开文件的记录,但是记录条数较少时却很正常,这是怎么回事,不知您遇见过没有,请赐教,先谢了:)
      

  7.   

    到apache的网站上面下载源程序
    可以具体点给个地址好吗
      

  8.   

    在Java中向Excel文件写入内容
    四、导出数据到Excel文件中
    下面的例子,设置了数字、日期的格式,还有字体,颜色等。File tempFile=new File("d:/temp/output.xls");
    WritableWorkbook workbook = Workbook.createWorkbook(tempFile);
    WritableSheet sheet = workbook.createSheet("TestCreateExcel", 0); //一些临时变量,用于写到excel中
    Label l=null;
    jxl.write.Number n=null;
    jxl.write.DateTime d=null;//预定义的一些字体和格式,同一个Excel中最好不要有太多格式
    WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLUE); 
    WritableCellFormat headerFormat = new WritableCellFormat (headerFont); WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED); 
    WritableCellFormat titleFormat = new WritableCellFormat (titleFont); WritableFont detFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); 
    WritableCellFormat detFormat = new WritableCellFormat (detFont); NumberFormat nf=new NumberFormat("0.00000");  //用于Number的格式
    WritableCellFormat priceFormat = new WritableCellFormat (detFont, nf); DateFormat df=new DateFormat("yyyy-MM-dd");//用于日期的
    WritableCellFormat dateFormat = new WritableCellFormat (detFont, df); //剩下的事情,就是用上面的内容和格式创建一些单元格,再加到sheet中
    l=new Label(0, 0, "用于测试的Excel文件", headerFormat);
    sheet.addCell(l);//add Title
    int column=0;
    l=new Label(column++, 2, "标题", titleFormat);
    sheet.addCell(l);
    l=new Label(column++, 2, "日期", titleFormat);
    sheet.addCell(l);
    l=new Label(column++, 2, "货币", titleFormat);
    sheet.addCell(l);
    l=new Label(column++, 2, "价格", titleFormat);
    sheet.addCell(l);//add detail
    int i=0;
    column=0;
    l=new Label(column++, i+3, "标题 "+i, detFormat);
    sheet.addCell(l);
    d=new DateTime(column++, i+3, new java.util.Date(), dateFormat);
    sheet.addCell(d);
    l=new Label(column++, i+3, "CNY", detFormat);
    sheet.addCell(l);
    n=new jxl.write.Number(column++, i+3, 5.678, priceFormat);
    sheet.addCell(n);i++;
    column=0;
    l=new Label(column++, i+3, "标题 "+i, detFormat);
    sheet.addCell(l);
    d=new DateTime(column++, i+3, new java.util.Date(), dateFormat);
    sheet.addCell(d);
    l=new Label(column++, i+3, "SGD", detFormat);
    sheet.addCell(l);
    n=new jxl.write.Number(column++, i+3, 98832, priceFormat);
    sheet.addCell(n);//设置列的宽度
    column=0;
    sheet.setColumnView(column++, 20);
    sheet.setColumnView(column++, 20);
    sheet.setColumnView(column++, 10);
    sheet.setColumnView(column++, 20);workbook.write();
    workbook.close();
      

  9.   

    POI中导出excel记录的条数有没有限制,为什么我导出达到2000条时显示:不能打开文件的提示,那位知道,告诉我,我马上可以揭帖了