Export datagrid to excel using Jquery Easyui(使用 Jquery Easyui 将数据网格导出到 excel)
问题描述
我是 json 新手.我使用 php 从 mysql 表生成了 jason 数据,并希望将生成的 json 导出为 .xls 格式.
I am new in json. I generated jason data from mysql table using php and want to export the generated json to .xls format.
examexport.php
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:
My php generated 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的代码:
Code for export to 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 未定义.
I want to send something like document.location='excel/examexport.php?entry=entry&batch=batch&semester=semester' I got a ReferenceError exportExcel is not defined.
推荐答案
在你的examexport.php 中,将 $_POST 更改为 $_GET 并使用以下函数:
In your examexport.php, change $_POST to $_GET and use the following function:
<input type="button" onclick="exportExcel()" value="Export to Excel " />
<script>
function exportExcel() {
var row=$('#dg').datagrid('getData');//to get the loaded data
if (row) {
url = "excel/examexport.php?entry="+$('#entry').val()+"&
semester="+$('#semester').val()+"&batch="+$('#batch').val();
window.open(url);
}
}
</script>
最后一句话,请浏览http://www.jeasyui.com/documentation/index.php.他们有很好的文档.
For final word, please go through http://www.jeasyui.com/documentation/index.php. they have good documentation.
这篇关于使用 Jquery Easyui 将数据网格导出到 excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Jquery Easyui 将数据网格导出到 excel
基础教程推荐
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01