Update Excel Content

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();
}