简体   繁体   中英

PhpSpreadsheet xlsx to PDF with mPDF -> I can't delete grid lines and show table borders

I am trying to generate a PDF invoice by XLSX template with phpspreadsheet.

Use php7.3 version, "mpdf/mpdf": "^8.0" and "phpoffice/phpspreadsheet": "^1.10"

$path = 'ejemplo2.xlsx';
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($path);
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($path);

$objPHPExcel->getActiveSheet()->getStyle('A:G')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setRGB('#ffffff');

$pdfPath = 'ejemplo2.pdf';
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Mpdf');
$writer->save($pdfPath);

The original xlsx and generated pdf look like: this

I tried to use $spreadsheet->getActiveSheet()->setShowGridLines(false); but so I can't show the table borders.

Does anybody know what I am doing wrong?

it probably has something to do with your version of php, seems like it is outdated, try to update it to the latest version. I had similar problem and updating my XAMPP fixed the problem.

我正在尝试使用 Dompdf 并运行正常。

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Dompdf');

I suggest you use the 3 pdf libraries Tcpdf, Dompdf and Mpdf, and try which one works for you. Because each of the 3 works differently and has strengths or weaknesses in others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM