怎么实现jqGrid导出excel

hhl_v 2010-07-05 06:13:32
怎么实现jqGrid导出excel


$("#AttentionList").jqGrid('navButtonAdd','#AttentionListPager',{
position:'last',title:'导出全部',caption:'',buttonicon:"ui-icon-disk",onClickButton:exportExcel
});


function exportExcel(){

alert("正在导出为Excel文件......请稍等");
//这里怎么实现导出的方法?

}
...全文
908 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fxs_lyz 2010-08-18
  • 打赏
  • 举报
回复
var products = _productRepository.GetAll();
var grid = new GridView();
grid.DataSource = from p in products
select new
{
ProductName = p.ProductName,
SomeProductId = p.ProductID
};
grid.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
return View("Index");
hoojo 2010-07-05
  • 打赏
  • 举报
回复

将grid的数据源通过后台代码导出excel即可。



<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

response.setHeader("Content-disposition", "attachment; filename=file.xls");//就这句,它就是excel
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'excel.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

</head>

<body>
<table>
//在这个表格中显示jqGrid的数据后,它就是一个excel了
</table>
</body>
</html>

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧