1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
function download_tpl(){ //$this->check_permission('orders', 'update', array('download', 'download_m')); $sep = DIRECTORY_SEPARATOR; $file_name = 'coupon_upload_tpl_origin.xls'; $tpl = FCPATH . 'assets' . $sep . 'admin' . $sep . 'excel_templates' . $sep . $file_name; $file_name = 'coupon_upload_tpl.xls'; $file = FCPATH . 'assets' . $sep . 'admin' . $sep . 'excel_templates' . $sep . $file_name; $file_url = base_url() . 'assets/admin/excel_templates/' . $file_name; // Initiate cache require(APPPATH.'libraries/PHPExcel.php'); $inputFileType = PHPExcel_IOFactory::identify($tpl); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($tpl); //選項sheet $worksheet = $objPHPExcel->getSheet(1); //logg($worksheet); //修改產品清單 $rowN = 2; $columnN = 5; $products = $this->b2c_products(); foreach($products as $key => $prod){ $worksheet->setCellValueByColumnAndRow($columnN, $rowN, $prod->title); $worksheet->setCellValueByColumnAndRow($columnN+1, $rowN, $prod->unique_id); $rowN++; } $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save($file); redirect($file_url); exit(); } |