我想将网页中的table表格导出到EXCEL中
谁有源代码啊 帮个忙啊 十分感谢

解决方案 »

  1.   

    想必你的table里面的值也是db里面的值。我觉得做个Excel魔板,然后直接用poi或第三方库写Excel就可以了,然后Download下来
      

  2.   

    response.setContentType("applicationpeng/ms-download");
    response.setHeader("Content-Disposition", "attachment;filename=Report.xls");
    String text="<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"></head><body><TABLE   border=1 align=center cellPadding=2 cellSpacing=1 width='100%'>"+request.getParameter("context")+"</table></body></html>";
    response.getWriter().println(text);
    response.getWriter().close();
    前一个页面放个span叫context。
      

  3.   

    偶用过POI  感觉还不错  lz试试  google baidu下好多这个例子~
      

  4.   

    POI还可以
    代码片断如下: 
    写Excel文件:
    private HSSFSheet ws = null;
                      HSSFRow xlsRow = ws.createRow(row);
    HSSFCell cell = xlsRow.createCell((short) col);
    cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    cell.setCellValue(nodeText);
    web方式下载文件:
    public void generateXlSFile(HttpServletResponse response) { String rootId = null;
    rootId = this.getRootId();
    try { BufferedOutputStream bos = new BufferedOutputStream(response
    .getOutputStream()); //FileOutputStream fos = new FileOutputStream(fileName);
    HSSFWorkbook wb = new HSSFWorkbook();
    ws = wb.createSheet();
    wb.setSheetName(0, this.getFileName(), (short) 1);
    //this.traveNode(rootId, 1, 1);
    wb.write(bos);
    bos.close(); } catch (IOException e) {
    //
    }
    }
    更详细的可以查阅POI的相关文档
      

  5.   

    貌似poi,jexcel都很不错,可以试试。
      

  6.   

    要支持rowSpan和colSpan还是挺麻烦的,还有数字右对齐等,pio可实现,我同事写了个,由于不是我写的不能贴出来呵呵,但是可以跟你说下,使用outerHTML替换些不支持的属性后分析下colSpan和rowSpan,有个对象可以干这事,最后把生成的流流出来就行了.
      

  7.   

    这里有个servlet的代码public class ApplesAndOranges extends HttpServlet
    {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException
    {
    response.setContentType("application/vnd.ms-excel");
    PrintWriter out = response.getWriter();
    out.println("\tQ1\tQ2\tQ3\tQ4\tTotal");
    out.println("Apples\t78\t87\t92\t29\t=SUM(B2:E2)");
    out.println("Oranges\t77\t86\t93\t30\t=SUM(B3:E3)");
    }
    }其实关键就是response.setContentType("application/vnd.ms-excel"); 
    你自己体会一下