如何使用jquery将jsp表下载为excel文件

时间:2012-08-18 11:47:44

标签: jquery jsp spring-mvc

我正在使用带有MVC的spring和jsp页面进行演示。我要求允许最终用户下载jsp中显示的表作为excel表。这些表包含我通过使用模型映射属性进行渲染,如下所示。

<div id="hotel_user">
<table width="98%" style="border:5px solid #999999" cellpadding="0" cellspacing="1" bgcolor="#CFD7E8">
<tr style="background-color:#72E076">
  <td width="auto" height="27" align="center">Date</td>
</tr>
<tr>
 <td width="0%" height="27" align="center" class="row2"><b>${aff.date_string}</b></td>
 <td width="auto" height="27" align="center"><b>${aff.no_of_posted} </b></td>
 <td width="auto" height="27" align="center"><b>${aff.no_of_listed}</b> </td>
</tr>
</table>
</div> 
  <input type="button" id="download" value="Download As Excell">

点击按钮,表格数据应作为excel下载。 我已经看到并试图实现代码,它在excel表中下载但是conatin null vale。 以下链接我已实施。     http://jsfiddle.net/n9XRx/

我在jquery中用过:

 $("#download").click(function() {  
 var hotel_user = $('#hotel_user').html();    
 window.open('data:application/vnd.ms-excel,' + $('#hotel_user').html());
});     

任何建议我都错了。 感谢。

1 个答案:

答案 0 :(得分:0)

您需要一种方法首先将html表中的数据转换为Excel文档。从this开始 您必须在服务器端生成文档,然后才能启动正确的下载。