laravel怎么可以把excel文件转为pdf文件?
尝试用PHPOffice/PhpSpreadsheet转换,写了个函数,如下:
备注:PhpSpreadsheet是PHPExcel的新版,https://github.com/PHPOffice/...
public function makePdf()
{
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('demo.xlsx');
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->getCell('A2')->setValue('Hello');
$worksheet->getCell('B2')->setValue('world');
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf');
$writer->save('demo.pdf');
}
但是有两个问题,一是excel的编码问题,中文会显示乱码,而是excel表格设置好的格式,也就是单元格大小被改变了(如下截图所示),应该怎么做?