PHPExcel icon indicating copy to clipboard operation
PHPExcel copied to clipboard

Not drawn borders in PDF (using mPDF-6.0)

Open gtitaev opened this issue 9 years ago • 4 comments

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. border

<?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;

gtitaev avatar Sep 16 '15 07:09 gtitaev

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.

ComputerTinker avatar Oct 14 '15 16:10 ComputerTinker

So what is the solution ? Everybody just referenced it all the way

sunjayaali avatar Dec 29 '16 05:12 sunjayaali

The solution suggested in PR #690 should be rebased on top of PhpSpreadsheet develop branch if the issue still exists.

PowerKiKi avatar Dec 29 '16 06:12 PowerKiKi

hi @xyluet , did you fix it?

martinfpas avatar Jan 29 '18 02:01 martinfpas