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:
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:
Jquery code:
- $ (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 ("_ URL _/memberExport/ids/" + ids );
- }
-
- });
- });
PHP code:
- // 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;
- }
- }
- }