1<?PHP2 Header("content-type:text/html; charset=gb2312 "); 3 error_reporting(E_all);4 Ini_set(' Display_errors ',TRUE);5 Ini_set(' Display_startup_errors ',TRUE);6 7 Define(' EOL ', (Php_sapi = = ' cli ')?Php_eol: ' <br/> ');8 9Date_default_timezone_set (' Europe/london ');Ten One /** Phpexcel_iofactory*/ A require_once dirname(__file__) . ‘/.. /classes/phpexcel/iofactory.php '; - $objReader= Phpexcel_iofactory::createreader (' Excel5 '); - //setting up template files the $objPHPExcel=$objReader->load ("Templates/bills.xls"); - //to convert a JSON string to an array - $billData= Json_decode ($_request["Billdata"],true); - //Fill Cells + $objPHPExcel->getactivesheet ()->setcellvalue (' B4 ',$billData[' Party ']) -->setcellvalue (' B5 ',$billData[' Game ']) +->setcellvalue (' A9 ',$billData[' Month ']) A->setcellvalue (' I28 ',$billData[' Total ']) at->setcellvalue (' H30 ',$billData[' Partyaccount '] [' Name ']) -->setcellvalue (' H31 ',$billData[' Partyaccount '] [' Bank ']) -->setcellvalue (' H32 ',$billData[' Partyaccount '] [' Account ']) -->setcellvalue (' H33 ',$billData[' Partyaccount '] [' Address ']) -->setcellvalue (' H34 ',$billData[' Partyaccount '] [' Contactpeople ']) - in->setcellvalue (' H35 ',$billData[' Partyaccount '] [' Contacttel ']); - to //loop fill the same header cell + $row=11; - foreach($billData[' Bills '] as $r=$dataRow) { the $objPHPExcel->getactivesheet ()->setcellvalue (' B ').$row,$dataRow[' Cardtype ']) *->setcellvalue (' C ').$row,$dataRow[' OrderAmount ']) $->setcellvalue (' D '.$row,$dataRow[' Feerate '])Panax Notoginseng->setcellvalue (' E '.$row,$dataRow[' Fee ']) -->setcellvalue (' F '.$row,$dataRow[' Amount ']) the->setcellvalue (' G '.$row,$dataRow[' Partyratio ']) +->setcellvalue (' H '.$row,$dataRow[' Partynumber ']) A->setcellvalue (' I ').$row,$dataRow[' Partyamount ']) the->setcellvalue (' J ').$row,$dataRow[' Memo ']); + $objPHPExcel->getactivesheet ()->getstyle (' C ').$row)->getborders ()->getbottom ()->setborderstyle (Phpexcel_style_border::Border_thin); - $row++; $ } $ - $objWriter= Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 '); - the $str= Mb_convert_encoding ("Out/bill_").$billData[' Party ']. ' _‘.$billData[' Game ']. ' _‘.$billData[' Month ']. ". XLS "," gb2312 "," UTF-8 "); - $objWriter->save ($str);Wuyi //allow access to the browser to download file streams directly the Header("Location:/out/bill_".$billData[' Party ']. ' _‘.$billData[' Game ']. ' _‘.$billData[' Month ']. ". XLS ");