Example of PHPExcel file import and export

Source: Internet
Author: User
PHPExcel import and export excel file instance publicstaticfunctionexportExcel ($ fileName, $ displayFields, $ exportList) {$ objExcelnewPHPExcel (); setdocumentProperty $ ob1_riterphpexcel_iofactor PHPExcel import and export excel file instance

Public static function exportExcel ($ fileName, $ displayFields, $ exportList)

{

$ ObjExcel = new PHPExcel ();

// Set document Property

$ ObjWriter = PHPExcel_IOFactory: createWriter ($ objExcel, 'excel2007 ');

$ ObjActSheet = $ objExcel-> getActiveSheet ();

$ Key = ord ("");

Foreach ($ displayFields as $ filedValue)

{

$ Colum = chr ($ key );

$ ObjActSheet-> setCellValue ($ colum. '1', $ filedValue );

$ Key + = 1;

}

$ Column = 2;

Foreach ($ exportList as $ key => $ rows ){

$ Span = ord ("");

Foreach ($ rows as $ keyName => $ value ){

$ J = chr ($ span );

$ ObjActSheet-> setCellValue ($ j. $ column, $ value );

$ Span ++;

}

$ Column ++;

}

//*************************************

$ Outfile = $ fileName. ". xls ";

// Export to exploer

Header ("Content-Type: application/force-download ");

Header ("Content-Type: application/octet-stream ");

Header ("Content-Type: application/download ");

Header ('content-Disposition: inline; filename = "'. $ outfile .'"');

Header ("Content-Transfer-Encoding: binary ");

Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");

Header ("Pragma: no-cache ");

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

Exit;

}


This is a small example of programming. here, mark, if you want to make a simple instance, you can use it directly, mainly for reading rows and columns.

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.