谁有例子,可以给我看一下吗?非常感谢!!!!

解决方案 »

  1.   

    用SQL或者ACCESS把EXCEL导入
    然后在JSP中直接引用就行了
      

  2.   

    有个包是专门针对Excel文件的操作的,具体的你可以Google一下
      

  3.   

    <%@ 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();
    %>