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.