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

Collapse Image named in Japanese. #2415

Closed
Kurogoma939 opened this issue Nov 26, 2021 · 0 comments · Fixed by #2416
Closed

Collapse Image named in Japanese. #2415

Kurogoma939 opened this issue Nov 26, 2021 · 0 comments · Fixed by #2416

Comments

@Kurogoma939
Copy link

What is the expected behavior?

I would like to draw image named in Japanese.

What is the current behavior?

If draw image in English title, It works. But in Japanese, it collapsed ...

What are the steps to reproduce?

<?php
public function sample(){
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $fileName = "sample";
        $sheet->setTitle("Title");
  
        $drawing = new Draw();
        $path = WWW_ROOT. 'img\サンプル.png';

        $drawing->setPath($path);
        $drawing->setCoordinates('B3');
        $drawing->setWorksheet($spreadsheet->getActiveSheet());

        
        $writer = new Xlsx($spreadsheet);
        $stream = new CallbackStream(function () use ($writer) {
            $writer->save('php://output');
        });

        return $this->response->withType('xlsx')
            ->withHeader('Content-Disposition', "attachment;filename=\"{$fileName}.xlsx\"")
            ->withBody($stream);
    }

Which versions of PhpSpreadsheet and PHP are affected?

PHPSpreadsheet 1.18
PHP 7.4
CakePHP4

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Nov 27, 2021
Fix PHPOffice#2415. Fix PHPOffice#1470. If path name of image contains anything other than ASCII, or if it contains # or space or probably other exceptions, PhpSpreadsheet creates a file that Excel cannot, for whatever reason, read (it is valid xml). When adding an image to a spreadsheet, Excel does not retain the original path name; PhpSpreadsheet does, but probably shouldn't. It is changed to save the image file in the zip as the MD5 hash of the original path name. This produces a file that Excel can read. In addition, it ensures that, if the image is used in multiple places, it is saved in the Excel file only once.

Because this error becomes evident only when opening the file in Excel, it is difficult to write a test case. I have instead duplicated sample Basic/05... using image files whose names match the reported error conditions.
oleibman added a commit that referenced this issue Dec 6, 2021
* Special Characters in Image File Name

Fix #2415. Fix #1470. If path name of image contains anything other than ASCII, or if it contains # or space or probably other exceptions, PhpSpreadsheet creates a file that Excel cannot, for whatever reason, read (it is valid xml). When adding an image to a spreadsheet, Excel does not retain the original path name; PhpSpreadsheet does, but probably shouldn't. It is changed to save the image file in the zip as the MD5 hash of the original path name. This produces a file that Excel can read. In addition, it ensures that, if the image is used in multiple places, it is saved in the Excel file only once.

Because this error becomes evident only when opening the file in Excel, it is difficult to write a test case. I have instead duplicated sample Basic/05... using image files whose names match the reported error conditions.

* Scrutinizer Minor Error

Remove some newly dead code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant