首先,是一段javascript脚本:
复制代码 代码如下:
/**
*
*
* @param table_id 表格的id
* @param container_id 容器的id
* @param form_id 提交表单的id
* @param title 文件名
* @param rownumbers
*/
function getXlsFromTbl(table_id, container_id ,form_id, title, rownumbers) {
try {
var content = "";
if (table_id != null && table_id != "" && table_id != "null") {
<SPAN style="WHITE-SPACE: pre"> </SPAN>content = getTblData($('#' + table_id), $('#' + container_id), rownumbers);
}
if (content == "") {
alert("表格不存在");
return;
}
var fileName = getExcelFileName(title);
doFileExport($('#' + form_id), fileName, content);
}
catch (e) {
alert("导出异常:" + e.name + "->" + e.description + "!");
}
}
function getTblData(tableobj, containerobj, rownumbers) {
var outStr = "";
if (tableobj != null) {
var rowdata = tableobj.getRowData();
var Lenr = 1;
for (i = 0; i < Lenr; i++) {
//var Lenc = curTbl.rows(i).cells.length;
var th;
if (rownumbers == false) {
th = containerobj.find('TH:not(:first-child)');
}
else {
th = containerobj.find('TH');
}
th.each(function(index, element) {
var j = index + 1;
var content = $(element).text();
content = content.replace(/(^\s*)|(\s*$)/g, "");//去掉空格
outStr += content + ",";
});
outStr += "+nl+";
}
var tmp = "";
for (i = 0; i < rowdata.length; i++) {
var row = eval(rowdata[i]);
for (each in row) {
<SPAN style="WHITE-SPACE: pre"> </SPAN>var temp = $(row[each]).text();
<SPAN style="WHITE-SPACE: pre"> </SPAN>if($(row[each]).text() == null || $(row[each]).text() == ""){
<SPAN style="WHITE-SPACE: pre"> </SPAN>if(row[each].charAt(0) != '<')
<SPAN style="WHITE-SPACE: pre"> </SPAN>outStr += row[each] + ",";
<SPAN style="WHITE-SPACE: pre"> </SPAN>
<SPAN style="WHITE-SPACE: pre"> </SPAN>}
<SPAN style="WHITE-SPACE: pre"> </SPAN>else
<SPAN style="WHITE-SPACE: pre"> </SPAN>outStr += $(row[each]).text() + ",";
}
outStr += "+nl+";
}
}
else {
outStr = null;
alert(inTbl + " null!");
}
return outStr;
}
function getExcelFileName(title) {
var d = new Date();
var curYear = d.getYear();
var curMonth = "" + (d.getMonth() + 1);
var curDate = "" + d.getDate();
var curHour = "" + d.getHours();
var curMinute = "" + d.getMinutes();
var curSecond = "" + d.getSeconds();
if (curMonth.length == 1) {
curMonth = "0" + curMonth;
}
if (curDate.length == 1) {
curDate = "0" + curDate;
}
if (curHour.length == 1) {
curHour = "0" + curHour;
}
if (curMinute.length == 1) {
curMinute = "0" + curMinute;
}
if (curSecond.length == 1) {
curSecond = "0" + curSecond;
}
var fileName = title + "_" + curYear + curMonth + curDate + "_"
+ curHour + curMinute + curSecond + ".csv";
return fileName;
}
function doFileExport(formobj, filename, content) {
<SPAN style="WHITE-SPACE: pre"> </SPAN>formobj.html("<input id='filename' name='filename' type='text' style='display: none'><input id='content' name='content' type='text' style='display: none'>");
$("#filename").val(filename);
$("#content").val(content);
formobj.submit();
}
接着是页面调用的javascript:
复制代码 代码如下:
<form id="download_form" method="post" target="_blank" action="downLoadTableDataAction">
复制代码 代码如下:
<div id="table_container">
<SPAN style="WHITE-SPACE: pre"> </SPAN><table id="keyword_detail"></table>
<SPAN style="WHITE-SPACE: pre"> </SPAN><div id="footer"></div>
</div>
复制代码 代码如下:
//下载
$('#download_file').click(function() {
getXlsFromTbl('keyword_detail', 'table_container' ,'download_form', '关键词详细数据', true)
});
jqgrid,表格数据
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- ABC唱片-鲍比达·新民乐《满江红》[APE+CUE]
- 许嵩.2014-不如吃茶去【海蝶】【WAV+CUE】
- 周笔畅.2024-HAVE.A.GOOD.NIGHT【SN.Music】【FLAC分轨】
- 周笔畅.2024-HAVE.A.NICE.DAY【SN.Music】【FLAC分轨】
- 证声音乐图书馆《真夏派对 x 迪斯可》[FLAC/分轨][380.78MB]
- 证声音乐图书馆《星空下 爵士钢琴》[320K/MP3][65.88MB]
- 证声音乐图书馆《星空下 爵士钢琴》[FLAC/分轨][283.95MB]
- 沙门怀一《竹山听雨HQ》头版限量[低速原抓WAV+CUE]
- 沙门怀一《于喁·壹HQ》头版限量编号[低速原抓WAV+CUE]
- 群星《魅音绝唱》黑胶CD【WAV】
- 腾格尔.2002-四十独白【风潮】【WAV+CUE】
- 陈明真.1992-到哪里找那么好的人【华星】【WAV+CUE】
- 黄凯芹.2012-廿五年3CD【环球】【WAV+CUE】
- 证声音乐图书馆《七夕 爵士情缘》[320K/MP3][64.8MB]
- 证声音乐图书馆《七夕 爵士情缘》[FLAC/分轨][327.79MB]