[php] 使用Jquery Easyui将datagrid导出为ex​​cel


Answers

$("#btnExport").click(function(e) {
window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#dg').html()));
e.preventDefault(); });

你可以使用简单的jQuery代码。 你应该在你的文件中添加jQuery库。

Question

我是JSON新手。 我使用PHP从MySQL表生成jason数据,并希望将生成的json导出为.xls格式。

examexport.php

<?php
    include 'conn.php';

    $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $semester = isset($_POST['semester']) ? 
    mysql_real_escape_string($_POST['semester']) : '';
    $entry = isset($_POST['entry']) ? mysql_real_escape_string($_POST['entry']) : '';
    $batch = isset($_POST['batch']) ? mysql_real_escape_string($_POST['batch']) : '';

    //phpexcel things go here
?>

我的PHP生成的json:

 {"total":"6","rows":
 [{"id":"2","regd":"25","name":"Lalhmangaihsangi","class":"BA",
"rollno":"3","univ_roll":"UNVI573","univ_no":"MZU876","core":"Education",
"semester":"First","batch":"2014","subject":"Education",
"entry":"Second Internal Test","date":"2014-07-23",
"score":"55","fm":"100","remark":"She is guarded"}]}

输出为excel的代码:

<input type="button" onclick="exportExcel()" value="Export to Excel " />
<script>                
  function exportExcel(){
    $('#dg').datagrid('load',{ //load data by semester/batch/entry
    semester: $('#semester').val(),
    batch: $('#batch').val(),
    entry: $('#entry').val(),
    document.location='excel/examexport.php'// How do I include entry/batch/ here?
 });
 }
</script>

我想发送像document.location ='excel / examexport.php?entry = entry&batch = batch&semester = semester'我得到一个ReferenceError exportExcel没有定义。




Links