먼저 자바스크립트 스크립트입니다.
/**
*
*
* @param table_id 테이블 ID
* @param Container_id 컨테이너 ID
* @param form_id 제출 양식 ID
* @param 제목 파일 이름
* @ 매개변수 행번호
*/
function getXlsFromTbl(table_id, Container_id ,form_id, title, rownumbers) {
try {
var content = "";
if (table_id != null && table_id != "" && table_id != "null") {
content = getTblData($('#' table_id), $('#' 컨테이너_id), rownumbers);
}
if (content == "") {
Alert("表格不存재");
반품;
}
var fileName = getExcelFileName(제목);
doFileExport($('#' form_id), fileName, content);
}
catch (e) {
Alert("导take异常:" 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.replace (/(^s*)|(s*$)/g, "");//去掉공格
outStr = content ",";
});
outStr = " nl ";
}
var tmp = "";
for (i = 0; i < rowdata.length; i ) {
var row = eval(rowdata[i]);
for (각 행) {
var temp = $(row[each]).text();
if($(row[each]).text() == null || $(row[each]).text() == ""){
if(row[each].charAt(0) != '<')
outStr = 행[각각] ",";
}
else
outStr = $(row[each]).text() ",";
}
outStr = " nl ";
}
}
else {
outStr = null;
경고(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) {
formobj.html("");
$("#filename").val(파일 이름);
$("#content").val(content);
formobj.submit();
}
接着是页face调사용용javascript:
< 양식 id="download_form" method="post" target="_blank" action="downLoadTableDataAction">
//다운로드
$(' #download_file' ).click(function() {
getXlsFromTbl('keyword_detail', 'table_container' ,'download_form', '키워드 상세 데이터', true)
})