我想使用以下代码从模板中使用php excel生成pdf文件:
//load our new PHPExcel library
$this->load->library('excel');
echo 'Library load succesfull';
//name the worksheet
$objPHPexcel = PHPExcel_IOFactory::load('/Applications/MAMP/htdocs/timesheet/files/Timesheet_template.xlsx');
echo 'Loading template successfull...';
$objWorksheet = $objPHPexcel->getActiveSheet();
$objWorksheet->getCell('C17')->setValue($td_3);
$objWorksheet->getCell('D17')->setValue($td_4);
$objWorksheet->getCell('E17')->setValue($td_5);
$objWorksheet->getCell('F17')->setValue($td_6);
$month = date('F');
$year = date('Y');
$data['user_data'] = $this->session->userdata('user');
$user_id = $data['user_data']["employee_id"];
$f_name = $data['user_data']["f_name"];
$s_name = $data['user_data']["s_name"];
$username = $data['user_data']["user_name"];
$title = $data['user_data']["title"];
$is_active = $data['user_data']["is_active"];
$employee_type = $data['user_data']["employee_type"];
// $filename = 'just_some_random_name.xlsx'; //save our workbook as this file name
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as .XLSX Excel 2007 format
echo 'ALMOST CREATING THE PDF FILE';
$objWriter = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = '/Applications/MAMP/htdocs/timesheet/system/helpers/dompdf';
$objWriter = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = '/Applications/MAMP/htdocs/timesheet/system/helpers/dompdf';
if (!PHPExcel_Settings::setPdfRenderer(
$objWriter, $rendererLibraryPath
)) {
die(
'Please set the $rendererName and $rendererLibraryPath values' .
PHP_EOL .
' as appropriate for your directory structure'
);
}
echo 'pdf creation almost starting';
// $objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel,'pdf');
$objWriter = new PHPExcel_Writer_PDF($objPHPexcel);
echo 'SUCCESS FULLY CREATED THE PDF FILE...';
$under_score = "_";
$year = preg_replace('/\s+/', '', $year);
$inputFileType = $username . $under_score . $month . $under_score . $year . ".pdf";
$objWriter->save("files/un_approved/" . $username . $under_score . $month . $under_score . $year . ".pdf");
我正在使用dompdf库将最终模板转换为pdf,但生成的文件已损坏且无法由Adobe Reder打开。请告知我应该采用的最佳方式是什么?