PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.36k stars 3.47k forks source link

TCPDF - Stroke thickness will not applied #1164

Closed Collie-IT closed 4 years ago

Collie-IT commented 5 years ago

This is:

What is the expected behavior?

If I use a borderstyle like \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR In the PDF the line should be the size of the borderstyle in case aboth small.

What is the current behavior?

The lines get the same thickness because in protected function getCSSBorderStyle($cssborder) of <path>/vendor/tecnickcom/tcpdf/tcpdf.php the Parameter count will be interpreted like

    $bprop = preg_split('/[\s]+/', trim($cssborder));
        $border = array(); // value to be returned
        switch (count($bprop)) {
            case 3: {
                $width = $bprop[0];
                $style = $bprop[1];
                $color = $bprop[2];
                break;
            }
            case 2: {
                $width = 'medium';
                $style = $bprop[0];
                $color = $bprop[1];
                break;
            }
            case 1: {
                $width = 'medium';
                $style = $bprop[0];
                $color = 'black';
                break;
            }
            default: {
                $width = 'medium';
                $style = 'solid';
                $color = 'black';
                break;
            }
        }

PHP spreedsheet sends 4 parameters ("X X X !important") and all goes to the default: case.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...
$sheet = $spreadsheet->getActiveSheet();
$sheet->getStyle("A1")->getBorders()->getTop()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Tcpdf');
$writer->save($tpath);

Which versions of PhpSpreadsheet and PHP are affected?

Tested with 1.8.2, 19.0

Collie-IT commented 5 years ago

The dirty hotfix is to set a fall trough at getCSSBorderStyle($cssborder)of <path>/vendor/tecnickcom/tcpdf/tcpdf.php

switch (count($bprop)) {
            case 4: //fall trough for "'!important'"
            case 3: {
                $width = $bprop[0];
                $style = $bprop[1];
                $color = $bprop[2];
                break;
            }
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

oleibman commented 4 months ago

Fixed in TCPDF#467