如题,谢谢了.

解决方案 »

  1.   

    刚写好的代码,还热的呢<%@ page import="java.io.OutputStream" %>
    <%@ page import="org.apache.poi.hssf.usermodel.*,java.util.*,"%>
    <%
    //Get criteria
    String xlsName =request.getParameter("xlsName");
    if (xlsName == null || xlsName.equals("")) xlsName = "newexcel.xls";
    else xlsName =xlsName + ".xls";
    //Set respond type for excel
    response.reset();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=" + xlsName);
    OutputStream os=response.getOutputStream();
    //Create excel workbook
    HSSFRow row;
    HSSFCell cell;
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Records"); row = sheet.createRow( (short) 0); 
    cell = row.createCell((short) 0);
    cell.setCellValue("ACCOUNT");
    cell = row.createCell((short) 1);
    cell.setCellValue("Fund");
    cell = row.createCell((short) 2);
    cell.setCellValue("Old Balance");
    cell = row.createCell((short) 3);
    cell.setCellValue("New Balance");
    cell = row.createCell((short) 4);
    cell.setCellValue("Charge Time");
    cell = row.createCell((short) 5);
    cell.setCellValue("Charge Type");
    cell = row.createCell((short) 6);
    cell.setCellValue("Operator");for (int i=1; i<100;i++)
    {
    pay=(PaymentVO)allRecord.get(i-1);
    row = sheet.createRow( (short) i); 
    cell = row.createCell((short) 0);
    cell.setCellValue("12345"); //cell.setCellValue(cdrVO.getCallNumber());
    cell = row.createCell((short) 1);
    cell.setCellValue("100"); //cell.setCellValue
    cell = row.createCell((short) 2);
    cell.setCellValue("0.0")
    cell = row.createCell((short) 3);
    cell.setCellValue("100.0");
    cell = row.createCell((short) 4);
    cell.setCellValue("2006-08-25");
    cell = row.createCell((short) 5);
    cell.setCellValue("web");
    cell = row.createCell((short) 6);
    cell.setCellValue("123456");
    }
           
            
    //Write to client side
    wb.write(os); 
    os.flush();
    os.close();
    %>
      

  2.   

    <%@ page import="java.io.OutputStream" %>
    <%@ page import="org.apache.poi.hssf.usermodel.*,java.util.*,"%>
    <%
    //Get criteria
    String xlsName =request.getParameter("xlsName");
    if (xlsName == null || xlsName.equals("")) xlsName = "newexcel.xls";
    else xlsName =xlsName + ".xls";
    //Set respond type for excel
    response.reset();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=" + xlsName);
    OutputStream os=response.getOutputStream();
    //Create excel workbook
    HSSFRow row;
    HSSFCell cell;
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Records"); row = sheet.createRow( (short) 0); 
    cell = row.createCell((short) 0);
    cell.setCellValue("ACCOUNT");
    cell = row.createCell((short) 1);
    cell.setCellValue("Fund");
    cell = row.createCell((short) 2);
    cell.setCellValue("Old Balance");
    cell = row.createCell((short) 3);
    cell.setCellValue("New Balance");
    cell = row.createCell((short) 4);
    cell.setCellValue("Charge Time");
    cell = row.createCell((short) 5);
    cell.setCellValue("Charge Type");
    cell = row.createCell((short) 6);
    cell.setCellValue("Operator");for (int i=1; i<100;i++)
    {
    pay=(PaymentVO)allRecord.get(i-1);
    row = sheet.createRow( (short) i); 
    cell = row.createCell((short) 0);
    cell.setCellValue("12345"); //cell.setCellValue
    cell = row.createCell((short) 1);
    cell.setCellValue("100"); //cell.setCellValue
    cell = row.createCell((short) 2);
    cell.setCellValue("0.0")
    cell = row.createCell((short) 3);
    cell.setCellValue("100.0");
    cell = row.createCell((short) 4);
    cell.setCellValue("2006-08-25");
    cell = row.createCell((short) 5);
    cell.setCellValue("web");
    cell = row.createCell((short) 6);
    cell.setCellValue("123456");
    }
           
            
    //Write to client side
    wb.write(os); 
    os.flush();
    os.close();
    %>
      

  3.   

    上面仁兄的代码太复杂,我也用过,还的用java的类,
    有没有简单的方法,比如一个纯粹的.htm或.jsp,怎么能转换成excel.
      

  4.   

    呵呵,有一个更好的方法,给钱请别人做!或者用crl+c和ctr+v慢慢弄,什么都不用想!
      

  5.   

    这个我做过,用excel做一个文件另存为jsp。然后把这个jsp放到工程里面,就像一个普通的jsp一样,把要导出的数据用<%%>写到页面里面。当客户端请求这个页面时就会弹出保存为excel的对话框了。
      

  6.   

    刚才说的少了一点。在文件头加<%@ page language="java" pageEncoding="GBK"
    contentType="application/vnd.ms-excel; charset=GBK"%> 这么一句,才能下载。