<body>
<form action="/BookInfoAction" method="post">
<table border="1" id="tb">
<tr>
<td>
书号
</td>
<td>
书名
</td>
<td>
作者
</td>
<td>
出版社
</td>
<td>
出版日期
</td>
<td>
操作
</td>
</tr>
<c:forEach var="book" items="${list}" begin="0" step="1">
<tr>
<td>
${book.bookId }
</td>
<td>
${book.bookName }
</td>
<td>
${book.bookAuthor }
</td>
<td>
${book.publishName }
</td>
<td>
${book.publishDate }
</td>
<td>
<input type="button" value="删除"
onclick="javascript:window.location='<%=basePath%>BookInfoAction.do?method=delete&bookId=${book.bookId}';">
<input type="button" value="更新"
onclick="javascript:window.location='<%=basePath%>BookInfoAction.do?method=findById&bookId=${book.bookId}';">
</td>
</tr>
</c:forEach>
</table>
</form>
以上是我的jsp代码,要求就是把action 传过来显示的table中的内容,导出到一个excle。。或者给点列子参考下

解决方案 »

  1.   

    用poi在后台实现 以前做过很多这样的功能
      

  2.   

    简单点呢就直接生成一个csv文件。稍微复杂点呢,就用poi或jxl。都很简单的,找个例子一看就会了
      

  3.   

    直接用csv导出就行了
    OutputStream os = response.getOutputStream(); CsvWriter csv = new CsvWriter(os, ',', Charset.forName("GBK")); csv.writeRecord(new String[]
    { "操作人", "日志类型", "操作", "操作对象", "操作时间", "登陆ip" });
      

  4.   

    正解!还有poi可以弄2007以上和2003版本的execl,而jxl只能弄2003版本的excel!lz看着选
      

  5.   

    建议用jxl,我刚刚才完成了这个功能。在后台生成前台下载就完成了啊
      

  6.   

    用POI很方便
    将数据传到JSP页面
    JSP页面代码大致如下
    response.setContentType("application/vnd.ms-excel");
    String fileName = java.net.URLEncoder.encode("报表名字.xls","UTF-8");
    response.addHeader("Content-Disposition","attachment;filename=" + fileName);//读取导出模板文件
        FileInputStream input = new FileInputStream(request.getRealPath("/files/export/模板名称.xls"));
       HSSFWorkbook wb = new HSSFWorkbook(input);
       HSSFSheet sheet = null;
       HSSFRow row = null;
       HSSFCell cell = null;
       int sheetIndex = 0;
       int starRow = 1;
       List<Map<String,String>> list = 数据
       sheet = wb.cloneSheet(0);
       wb.setSheetName(sheetIndex + 1, "Sheet" + sheetIndex);
       for(int i = 0; i < list.size(); i++){
       Map map = (Map)list.get(i);
    starRow = starRow+1;
              sheet.shiftRows(starRow, sheet.getLastRowNum(), 1,true,false);
    row = sheet.getRow(starRow);
    cell = row.createCell(0);
    cell.setCellValue(map.get("ordergamename")==null?"":map.get("ordergamename").toString());
    cell = row.createCell(1);
    cell.setCellValue(map.get("US") == null ? "" : map.get("US").toString());
    cell = row.createCell(2);
    cell.setCellValue(map.get("EU") == null ? "" : map.get("EU").toString());
    cell = row.createCell(3);
    cell.setCellValue(map.get("SAIA") == null ? "" : map.get("SAIA").toString());
    cell = row.createCell(4);
    cell.setCellValue(map.get("num") == null ? "" : map.get("num").toString());
    cell = row.createCell(5);
    cell.setCellValue(map.get("complete") == null ? 0 : Double.valueOf(map.get("complete").toString()));
    cell = row.createCell(6);
    cell.setCellValue(map.get("unfinished")== null ? 0 : Double.valueOf(map.get("unfinished").toString()));
    cell = row.createCell(7);
    cell.setCellValue(map.get("money") == null ? "" : map.get("money").toString());
    cell = row.createCell(8);
    cell.setCellValue(map.get("beizhu")== null ? "" : map.get("beizhu").toString());
       }
           
        
      
             
       }
       //选中第二个Sheet
       wb.getSheetAt(1).setSelected(true);
       //移除第一个Sheet,第一个Sheet为模板Sheet,需要移除
       wb.removeSheetAt(0);
      
       //以文件的形式输出到页面
       out.clear();
                    out = pageContext.pushBody();
       ServletOutputStream ouput = response.getOutputStream();
    wb.write(ouput);

    //关闭文件流等操作
    wb = null;
    sheet = null;
       row = null;
       cell = null;
    input.close();
    ouput.flush(); 
    ouput.close();
      

  7.   

    如果你的输出页面是jsp页面,试试在你输出的页面加上这个:
    <%@ page language="java" contentType="application/vnd.ms-excel;charset=UTF-8"%>
      

  8.   

    用poi或jxl,找例子看看。poi对每个单元格可设置样式,高宽、字体、合并单元格。
    代码比较冗余。思路很简单。
      

  9.   

    毛线,我用的jxl照样导出2007的,而且假如用poi导出的话,数据量大之后很容易内存溢出
      

  10.   

    之前只用过jxl  现在又知道有poi等等 又学一招
      

  11.   

    请问你jxl导的excel 文件后面的格式是.xlsx吗?是的话求教!呵呵!我做的是财务和高速部分的数据!数据量不知道多大呢!占时没遇到溢出的问题呢