首頁  >  文章  >  web前端  >  jqgrid 表格資料匯出實例_javascript技巧

jqgrid 表格資料匯出實例_javascript技巧

WBOY
WBOY原創
2016-05-16 17:13:221584瀏覽

首先,是一段javascript腳本:

複製程式碼 程式碼如下:

/**
 * 
 * 
 * @param table_id 表格的id
 * @param container_id 容器的id
 * @param form_id 提交表單的id  * @param rownumbers
 */ 
function getXlsFromTbl(table_id, container_id ,form_id, title, rownumbers) { 
 
        if (table_id != null && table_id != "" && table_id != "null") { 
    '#'table_id), $('#'container_id), rownumbers); 
        } 
       
            返回;
        } 
        var fileName = getExcelFileName(title); 

    } 
    catch (e) { 
        alert("匯出例外:" e.name "->" e.description "!"); 
    } 

Datafunction getTblm(tabled) conpampero; > 
    var outStr = ""; 
    if (tableobj != null) { 
        

 
for (i = 0; i             //var Lenc = curTbl.rows(i).cells.length;           if (rownumbers == false) { 
                th = containerobj.find('TH:not(:first-child)'); 
    else { 
                th = containerobj.find('TH'); 
      >            th.each(函數(索引, 元素) { 
               content = $(element).text(); 
                內容物= 內容.替換(/(^s* )|(s*$)/g, "");//去掉空格  
               outStr = content ",";          } 
        var tmp = ""; 
        for (i = 0; i             var row = eval(rowdata[i]); 
            for (each in row) { 
                       
               if($(row[each]).text() === null || $(row[each]).text() ==[each]).text() === null || $(row[each]).text() == ""){ 
                       outStr = row[each] ","; 
                   
               else  outStr = $ (row[each]).text() ","; 
           } 
            🎜>    else { 
        outStr = null; 🎜> alert (inTbl " null!"); 
    } 
    return outStr; 

function getExcelFileName(title) {p d . getYear(); 
    var curMonth = "" (d.getMonth() 1); 
    var curDate = "" d.getDate(); 
 🎜>    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 "_" 
        

 
   回傳檔案名稱; 

function doFileExport(formobj, 檔案名稱, 內容) { 
; formobj.html(""); 
    $("#filename").val(檔名); 
    $("#content").val(content); 
    formobj.submit(); 
}  




連接是頁面調用的javascript:



複製代碼

代碼如下:


 

複製程式碼 程式碼如下:

 SPAN style="WHITE-SPACE: pre">
 
 
 

複製程式碼 程式碼如下:
//下載 ).click(function() { 
    getXlsFromTbl('keyword_detail', 'table_container' ,'download_form', '關鍵字詳細資料', true) 
}); 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn