Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more determine statements in CSSArray parsing function #304

Closed
zsimple opened this issue Dec 27, 2017 · 2 comments
Closed

Add more determine statements in CSSArray parsing function #304

zsimple opened this issue Dec 27, 2017 · 2 comments

Comments

@zsimple
Copy link

zsimple commented Dec 27, 2017

This is:

- [ ] a bug report
- [x] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

I am using WPS which is really popular in China, while it is not exactly compatible with Microsoft Excel. When reading in an excles file, it throws an exception, which happend in toCSSArray in file Reader/Xlsx.php.

What is the current behavior?

    private static function toCSSArray($style)
    {
        $style = str_replace(["\r", "\n"], '', $style);

        $temp = explode(';', $style);
        $style = [];
        foreach ($temp as $item) {
            $item = explode(':', $item);

            if (strpos($item[1], 'px') !== false) {
                $item[1] = str_replace('px', '', $item[1]);
            }
            // ...

It expects the string $item has format like "xxx:xxx", but $item string can be only an empty string.

What are the steps to reproduce?

Sorry it relate to the WPS software and can not reapear only with phpSpreadsheet, and it is more likely a WPS bug rather than phpSpreadsheet's. But it weill be very kind and easy to fix the problem with next code. I think it will help phpSpreadsheet to fit more nonstandard software.

    private static function toCSSArray($style)
    {
        $style = str_replace(["\r", "\n"], '', $style);

        $temp = explode(';', $style);
        $style = [];
        foreach ($temp as $item) {
            $item = explode(':', $item);
            if (count($item) != 2) {             // <---- Add this if
                continue;
            }

            if (strpos($item[1], 'px') !== false) {
                $item[1] = str_replace('px', '', $item[1]);
            }
            // ...

Thanks!

Which versions of PhpSpreadsheet and PHP are affected?

The latest version 27d83b4.

@PowerKiKi
Copy link
Member

Could you please give me the result of var_dump($style) when it fails ?

@zsimple
Copy link
Author

zsimple commented Dec 27, 2017

Of couse, it is position:absolute;left:0pt;top:0pt;margin-left:0pt;margin-top:0pt;height:24pt;width:77.25pt; . The last ";" makes something wrong by my opion.

PowerKiKi added a commit that referenced this issue Jan 28, 2018
- Support for PHP 7.2
- Support cell comments in HTML writer and reader - [#308](#308)
- Option to stop at a conditional styling, if it matches (only XLSX format) - [#292](#292)
- Support for line width for data series when rendering Xlsx - [#329](#329)

- Better auto-detection of CSV separators - [#305](#305)
- Support for shape style ending with `;` - [#304](#304)
- Freeze Panes takes wrong coordinates for XLSX - [#322](#322)
- `COLUMNS` and `ROWS` functions crashed in some cases - [#336](#336)
- Support XML file without styles - [#331](#331)
- Cell coordinates which are already a range cause an exception [#319](#319)
Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this issue Nov 20, 2018
Valid CSS style can end with `;` and that is the case for some 3rd party
software such as WPS Office.

Closes PHPOffice#304
Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this issue Nov 20, 2018
- Support for PHP 7.2
- Support cell comments in HTML writer and reader - [PHPOffice#308](PHPOffice#308)
- Option to stop at a conditional styling, if it matches (only XLSX format) - [PHPOffice#292](PHPOffice#292)
- Support for line width for data series when rendering Xlsx - [PHPOffice#329](PHPOffice#329)

- Better auto-detection of CSV separators - [PHPOffice#305](PHPOffice#305)
- Support for shape style ending with `;` - [PHPOffice#304](PHPOffice#304)
- Freeze Panes takes wrong coordinates for XLSX - [PHPOffice#322](PHPOffice#322)
- `COLUMNS` and `ROWS` functions crashed in some cases - [PHPOffice#336](PHPOffice#336)
- Support XML file without styles - [PHPOffice#331](PHPOffice#331)
- Cell coordinates which are already a range cause an exception [PHPOffice#319](PHPOffice#319)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants