DWZ and thinkphp consolidated data export to an Excel instance _php instance

Source: Internet
Author: User

This article illustrates the method of exporting data to Excel with DWZ and thinkphp consolidation. Share to everyone for your reference. The specific methods are as follows:

This problem has plagued me for a long time, and finally I wrote jquery to get it fixed, I hope to be able to meet the same problem with the help of people, OK, the following is the source code:

The jquery code is as follows:

Copy Code code as follows:
$ (function () {

The _getids method is to get the ID of the selected data to be exported, set two parameters selectedids--the input name of the selected ID,targettype--> fragmentation mode, the default is Navtab, if it is dialog's own modification
function _getids (selectedids,targettype) {
var ids= "";
var $box =targettype== "Dialog" $.pdialog.getcurrent (): Navtab.getcurrentpanel ();
$box. Find ("input:checked"). Filter ("[Name= '" +selectedids+ "]"). each (function (i) {

var val=$ (this). Val ();
Ids+=i==0?val: "," +val;});
return IDs;
}
triggered when you export the Excel button Class=iconn,click
$ (". iCONN"). Click (
function () {
Because this method applies directly to the parameter variables that are exported to Excel, so here's what I wrote.
var targettype= "Navtab";
var selectedids= "IDs";
var posttype= "string";//Bulk selection, in the form of text
var ids=_getids (Selectedids,targettype);
if (!ids) {
Alertmsg.error ($ (". iCONN"). attr ("warn"));
return false;
Alert ("Please select the data you want to export!") ");
}else{
Pass the acquired IDs to background processing
window.open ("__url__/memberexport/ids/" +ids);
}

});
});

The PHP code is as follows:
Copy Code code as follows:
Member information export to Excel
Public Function Memberexport () {
$id =$_request[' IDs '];//get the ID of the selected data
echo $id;

Export here to Excel I did not use Phpexcel, is written by myself, very simple, I believe we all understand what it means, according to their own needs to modify the line
$filename =date (' y-m-d ');
Header ("Pragma:public");
Header ("expires:0");
Header ("cache-control:must-revalidate,post-check=0,pre-check=0");
Header ("Content-type:application/force-download");
Header ("content-type:application/vnd.ms-execl;charset=gb2312");
Header ("Content-type:application/octet-stream");
Header ("Content-type:application/download");
Header (' Content-disposition:attachment;filename= '. $filename. ') XLS "');
Header ("Content-transfer-encoding:binary");
if (! $id) {
$this->error (' Illegal operation! ');
}else{

$map [' id ']=array (' in ', $id);
$title = "User name \ t name \ t department \ t job \ t ID \ \ t qualification \ t graduation time \ t employment time";
$title =iconv (' utf-8 ', ' GBK ', $title);
echo $title;
Set_time_limit (0);
$offset = 0;
$length = 100;
$Member = M (' member ');
$list = $Member->where ($map)->order (' id desc ')->select ();
if (! $list) {
$this->error (' Operation Error! ');
}else{
foreach ($list as $key => $row) {
echo "\ n";
echo iconv (' Utf-8 ', ' GBK ', $row [' username ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' name ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' Department ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' Zhiwu ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' SFZ ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' Zhicheng ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' Xueli ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' Bytime ']). " \ t ";
echo iconv (' Utf-8 ', ' GBK ', $row [' Lytime ']). " \ t ";

}
$offset + + $length;
}
}
}

I hope this article will help you with the PHP program design based on thinkphp framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.