PHPExcel
PHPExcel copied to clipboard
Not drawn borders in PDF (using mPDF-6.0)
The mPDF-6.0 does not draw the border.
And after "setBorderStyle()" some error with height in rows 6 and 9.
PHPExcel 1.8.1, mPDF-6.0.
<?php
require_once '../libs/PHPExcel/Classes/PHPExcel.php';
$mPDFLibraryPath = '../libs/mPDF-6.0';
// Create Excel
$objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$objWorksheet->setCellValue('A1', 'test-A1');
$objWorksheet->setCellValue('B1', 'test-B1');
$objWorksheet->setCellValue('A2', 'test-A2');
$objWorksheet->setCellValue('B2', 'test-B2');
$objWorksheet->setCellValue('A5', 'test-A5');
$objWorksheet->setCellValue('B5', 'test-B5');
$objWorksheet->setCellValue('C5', 'test-C5');
$objWorksheet->setCellValue('A8', 'test-A8');
$objWorksheet->setCellValue('B8', 'test-B8');
$objWorksheet->setCellValue('C8', 'test-C8');
$objPHPExcel->getActiveSheet()->getStyle('A5:C6')
->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A8:C9')
->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
// Redirect output
$fileFormat = 'pdf';
$fileName = "test";
if ($fileFormat == 'pdf') {
PHPExcel_Settings::setPdfRenderer(PHPExcel_Settings::PDF_RENDERER_MPDF, $mPDFLibraryPath);
$objPHPExcel->getActiveSheet()->setShowGridLines(false);
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="'.$fileName.'.pdf"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
} else { // Excel
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$fileName.'.xlsx"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
}
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
exit;
Incorrect HTML rendering is the cause of this issue, since the PDF is rendered from HTML output. See https://github.com/PHPOffice/PHPExcel/issues/690 as a related bug report.
So what is the solution ? Everybody just referenced it all the way
The solution suggested in PR #690 should be rebased on top of PhpSpreadsheet develop branch if the issue still exists.
hi @xyluet , did you fix it?