我使用过 tcpdf,也曾尝试使用 dompdf,但不适用于 php 7.1 或更高版本。
以下是我的代码:
public function exporttasklist(Request $request, Job $job)
{
$pathToFile = storage_path('app/xls/task.xlsx'); // find the xltx file
Excel::load($pathToFile, function ($doc) use ($job) {
$tasks = Task::where('job_id', $job->id)
->orderBy('created_at', 'DESC')
->get();
$Company = Company::where('id', $job->company_id)->first();
$sheet = $doc->setActiveSheetIndex(0); // access to sheet 1
$sheet->setCellValue('C4', $job->JobNo);
$sheet->setCellValue('C5', $job->JobName);
$sheet->setCellValue('L4', $Company->CompanyName);
$sheet->setCellValue('L5', $Company->CompanyChineseName);
$sheet->getStyle('L5')->getFont()->setName('msungstdlight');
$sheet->setCellValue('P4', $job->JobTranslationDirection);
$sheet->setCellValue('P5', $job->JobTranslationTeam);
$sheet->setCellValue('R5', $job->JobSales);
$styleArray2 = array(
'borders' => array(
'top' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
),'bottom' => array(
'style' => PHPExcel_Style_Border::BORDER_NONE,
),'left' => array(
'style' => PHPExcel_Style_Border::BORDER_NONE,
),'right' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
),
),
);
$sheet->getStyle('A7')->applyFromArray($styleArray2)
}
})->export('pdf');