Data exported from Dwz and thinkphp to an Excel instance

Source: Internet
Author: User
This article mainly introduces how to export data from Dwz and thinkphp to Excel. It is an Excel export technique based on the jQuery and ThinkPHP frameworks and is of great practical value, for more information, see

This article mainly introduces how to export data from Dwz and thinkphp to Excel. It is an Excel export technique based on the jQuery and ThinkPHP frameworks and is of great practical value, for more information, see

This document describes how to export data from Dwz and thinkphp to Excel. Share it with you for your reference. The specific method is as follows:

This problem has plagued me for a long time, and I finally wrote JQUERY to confuse it. I hope it will help people who encounter the same problem. Well, the source code is as follows:

The jquery code is as follows:

The Code is as follows:

$ (Function (){

// The _ getIds method is used to obtain the ID of the selected data to be exported. Two parameters are set: selectedIds -- input name of the selected id, targetType --> fragment mode. The default value is navTab, if it is a self-modified dialog
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;
}
// Export the excel button class = iconn, triggered when you click
$ (". Iconn"). click (
Function (){
// Because this method is directly used to export data to excel, I directly wrote the required parameter variables.
Var targetType = "navTab ";
Var selectedIds = "ids ";
Var postType = "string"; // If selected in batches, it is obtained in text format.
Var ids = _ getIds (selectedIds, targetType );
If (! Ids ){
AlertMsg. error ($ (". iconn"). attr ("warn "));
Return false;
// Alert ("select the data to export! ");
} Else {
// Send the obtained ids to the background for processing.
Window. open ("/index. php/Article/memberExport/ids/" + ids );
}

});
});


The PHP code is as follows:

The Code is as follows:

// Export member information to excel
Public function memberExport (){
$ Id = $ _ REQUEST ['id']; // obtain the ID of the selected data
// Echo $ id;

// I didn't use phpexcel to export data to excel here. It was very easy to write by myself. I believe everyone understands what it means. Just modify it as needed.
$ 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 = "'.w.filename.'.xls "');
Header ("Content-Transfer-Encoding: binary ");
If (! $ Id ){
$ This-> error ('invalid operation! ');
} Else {

$ Map ['id'] = array ('in', $ id );
$ Title = "USERNAME \ t name \ t Department \ t title \ t ID card \ t title \ t degree \ t Graduation time \ t recruitment 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 ['xulil']). "\ 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 design PHP programs based on the 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.