本文主要是介绍phpExcel 生成快递单,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
require_once 'PHPExcel.php';//定义路径$filePath = UPLOAD_PATH.'/shiptemplate/yt_excel.xls';$objPHPExcel = PHPExcel_IOFactory::load($filePath);$raw_data = $objPHPExcel->setActiveSheetIndex(0)->toArray();$data = array();$pname = '';foreach($n_ship as $nk=>$nval){for($i=0; $i<count($nval['product_name']); $i++){if(!$i){$pname = $nval['product_name'][$i];}else{$pname .= ",".$nval['product_name'][$i];}}foreach($raw_data as $key => $value){foreach($value as $k => $v){if($v == "{% company %}"){$value[$k] = str_replace('{% company %}', '轻轻去去去', $v);}elseif($v == "{% f_address %}"){$value[$k] = str_replace('{% f_address %}', '恩恩额', $v);}elseif($v == "{% consignee %}"){$value[$k] = str_replace('{% consignee %}', 点点滴滴, $v);}elseif($v == "{% f_telephone %}"){$value[$k] = str_replace('{% f_telephone %}', '15031456789', $v);}elseif($v == "{% product_name %}"){$value[$k] = str_replace('{% product_name %}', $pname, $v);}elseif($v == "{% t_address %}"){$value[$k] = str_replace('{% t_address %}', $nval['address'], $v);}elseif($v == "{% telephone %}"){$value[$k] = str_replace('{% telephone %}', $nval['telephone'], $v);}elseif($v == "{% c_time %}"){$value[$k] = str_replace('{% c_time %}', date("Y/m/d",time()), $v);}elseif($v == "{% s_address %}"){$value[$k] = str_replace('{% s_address %}', " ", $v);}elseif($v == "{% t_company %}"){$value[$k] = str_replace('{% t_company %}', " ", $v);}}$reset_key = 0;if ($nk){$reset_key = count($data)+10;}$data[$reset_key+$key] = $value;}}$objPHPExcel->setActiveSheetIndex()->fromArray($data, null, "A1");$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');ob_end_clean();$cancel_time="KD".date("YmdHis");if(!file_exists('upload/excel')){mkdir( 'upload/excel' , 0777 , true );}$filename = "upload/excel/".$cancel_time."_ship.xls";$objWriter->save($filename);
这篇关于phpExcel 生成快递单的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!