代码过程是,读取模板文件template.xls。写入对应内容,导出pdf文件。template.xls文件内容带有表格和日文。 个人认为是没有字体的原因,但是如何对应,望大虾告知!!!
require_once 'excel/PHPExcel.php';
$objPHPExcel = PHPExcel_IOFactory::load( "template.xls" );
$objPHPExcel->setActiveSheetIndex(0);
$objWorksheet = $objPHPExcel->getActiveSheet();
//写内容
$objWorksheet->getCell("C1")->setValue("test");
//假如图片
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('stamp');
$objDrawing->setDescription("aaaa");
$objDrawing->setPath("images/p1.jpg");
$objDrawing->setCoordinates('M1');
$objDrawing->setOffsetX(25);
$objDrawing->setRotation(36);
$objDrawing->setHeight(73);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($objWorksheet);
$objWorksheet->setTitle('Simple');
ob_end_clean();
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="detail.pdf"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->save('php://output');
exit;
------解决思路----------------------
確定內容文字是UTF-8编码嗎?如果不是就要用iconv轉換編碼。
------解决思路----------------------
phpexcel生成pdf有一个重大的缺陷:excel中如果有图片,生成的pdf里不会保留,所以你用这个来生成pdf文件不是最好的方案!