One-click excel export and excel Export

Source: Internet
Author: User

One-click excel export and excel Export

How to export an excel file with one click

Public function input (){

Ob_end_clean (); // clear the buffer to avoid garbled characters.

Header ("Content-Typ: text/html; charset = UTF-8 ");

Vendor ('excel. PHPExcel. Writer. iwrite ');

Vendor ('excel. PHPExcel. Writer. excel5 ');

Vendor ('excel. PHPExcel ');

Vendor ('excel. PHPExcel. IOFactory ');

$ ObjPHPExcel = new PHPExcel ();

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('a1', "ID"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('b1 ', "Studentname"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('c1', "IDcard"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('d1 ', "StudentID"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('e1 ', "ClassID"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('f1 ', "Sex"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('g1', "Nation"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('h1 ', "Birth"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('i1', "Imagepath"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('j1', "Huji"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('k1 ', "Phone"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('l1', "QQ"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('m1 ', "Email"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('n1 ', "Addressnow"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('o1 ', "Local"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('p1', "Position"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('q1', "Macrosoft"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('r1', "CoachID"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('s1', "CarID"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('t1', "CartypeID"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('u1', "Introducer"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('v1 ', "Signdate"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('w1', "Signplace"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('x1 ', "Signgtype"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('y1 ', "Lubiao"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('z1 ', "Lubiaodate"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('aa1', "Zhika"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ab1', "Zhikadate"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ac1', "Subtabdate"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ad1', "Begindate"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ae1 ', "Bigtabdate"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('af1', "Weier"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ag1', "Lixiao"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ah1', "Fingerprint"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ai1', "Inform"); // set the column Value

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('aj1', "SchoolID"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('ak1', "Setting"); // you can specify the column value.

$ ObjPHPExcel-> getActiveSheet ()-> setCellValue ('al1', "Remarks"); // set the column Value

$ SQL ['lixiao'] = 'no ';

$ SQL ['schoolid'] = "$ _ SESSION [SchoolID]";

$ Studentname = I ('studentname ');

$ Idcard = I ('idcard ');

If ($ studentname! = ''){

$ SQL ['studentname'] = "$ Studentname ";

}

If ($ idcard! = ''){

$ SQL ['idcard'] = "$ IDcard ";

};

$ SQL ['_ logic'] = 'AND ';

$ Arr = M ('studentinfo')-> where ($ where)-> select ();

$ Count = count ($ arr); // you can find the number of rows;

$ I = 2; // note that this is 2, because the header information has been set in the first line.

For ($ j = 0; $ j <$ count; $ j ++ ){

$ ObjPHPExcel-> setActiveSheetIndex (0)

-> SetCellValue ('A'. $ I, $ arr [$ j] ['id']) // note that there is no semicolon ending here

-> SetCellValue ('B'. $ I, $ arr [$ j] ['studentname'])

-> SetCellValue ('C'. $ I, $ arr [$ j] ['idcard '])

-> SetCellValue ('D'. $ I, $ arr [$ j] ['studentid'])

-> SetCellValue ('E'. $ I, $ arr [$ j] ['classid '])

-> SetCellValue ('F'. $ I, $ arr [$ j] ['sex'])

-> SetCellValue ('G'. $ I, $ arr [$ j] ['nation'])

-> SetCellValue ('H'. $ I, $ arr [$ j] ['birth'])

-> SetCellValue ('I'. $ I, $ arr [$ j] ['ImagePath'])

-> SetCellValue ('G'. $ I, $ arr [$ j] ['huji'])

-> SetCellValue ('K'. $ I, $ arr [$ j] ['phone'])

-> SetCellValue ('L'. $ I, $ arr [$ j] ['qq'])

-> SetCellValue ('M'. $ I, $ arr [$ j] ['email '])

-> SetCellValue ('n'. $ I, $ arr [$ j] ['address'])

-> SetCellValue ('O'. $ I, $ arr [$ j] ['local'])

-> SetCellValue ('P'. $ I, $ arr [$ j] ['position'])

-> SetCellValue ('q'. $ I, $ arr [$ j] ['macrosoft '])

-> SetCellValue ('R'. $ I, $ arr [$ j] ['coachid'])

-> SetCellValue ('s '. $ I, $ arr [$ j] ['carid'])

-> SetCellValue ('T'. $ I, $ arr [$ j] ['cartypeid'])

-> SetCellValue ('u'. $ I, $ arr [$ j] ['troducer '])

-> SetCellValue ('V'. $ I, $ arr [$ j] ['signature'])

-> SetCellValue ('W'. $ I, $ arr [$ j] ['signature'])

-> SetCellValue ('x'. $ I, $ arr [$ j] ['signgtype'])

-> SetCellValue ('y'. $ I, $ arr [$ j] ['lubiao'])

-> SetCellValue ('Z'. $ I, $ arr [$ j] ['lubiaodate'])

-> SetCellValue ('aa'. $ I, $ arr [$ j] ['zhika '])

-> SetCellValue ('AB'. $ I, $ arr [$ j] ['zhikadate'])

-> SetCellValue ('ac'. $ I, $ arr [$ j] ['subtabdate'])

-> SetCellValue ('ad'. $ I, $ arr [$ j] ['begindate'])

-> SetCellValue ('AE'. $ I, $ arr [$ j] ['bigtabdate'])

-> SetCellValue ('af'. $ I, $ arr [$ j] ['weier '])

-> SetCellValue ('ag'. $ I, $ arr [$ j] ['lixiao'])

-> SetCellValue ('Ah'. $ I, $ arr [$ j] ['fingerprint '])

-> SetCellValue ('ai'. $ I, $ arr [$ j] ['inform'])

-> SetCellValue ('aj '. $ I, $ arr [$ j] ['schoolid'])

-> SetCellValue ('ak'. $ I, $ arr [$ j] ['setting'])

-> SetCellValue ('al'. $ I, $ arr [$ j] ['remark']);

$ I ++;

}

$ ObjPHPExcel-> getActiveSheet (0)-> setTitle ('studentinfo ');

$ ObjPHPExcel-> setActiveSheetIndex (0 );

Header ('content-Type: application/vnd. ms-excel ');

Header ('content-Disposition: attachment; filename = "studentinfo.xls "');

Header ('cache-Control: max-age = 0 ');

$ ObjWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, 'excel5 ');

$ ObjWriter-> save ('php: // output ');

}

Html file

<Div style = "float: right"> <formaction = "{: U ('input ')} "> <input type =" submit "value =" one-click EXCEL export "> </form> </div>

 

Related Article

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.