Skip to content

Add more determine statements in CSSArray parsing function #304

@zsimple

Description

@zsimple

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions