Ask questionsCorrupt XLSX file when drawing image

This is:

- [* ] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on or

I wanted to download xlsx file in which added image file with phpspreadsheet. Then I am facing issue of excel file broken due to "$drawing" as below source code.

What is the expected behavior?

No error when open the excel file.

What is the current behavior?

When opened the xlsx file, it always asked if fix to see.

What are the steps to reproduce?

Kindly try below code...

// add code that show the issue here...

use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheet\Writer\CSV as CSVWriter;

class TestsController extends AppController{

public function output(){

    //read template
    $reader = new XlsxReader();
    $spreadsheet = $reader->load(WWW_ROOT.'files/template/empty.xlsx');
    $sheet = $spreadsheet->getActiveSheet();

    //add image in excel
    $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();

    //create tmp file
    $tmp_path = WWW_ROOT.'files/test_tmp.xlsx';
    $writer = new XlsxWriter($spreadsheet);

    $content = 'attachment;';
    $content .= 'filename*=UTF-8\'\''.rawurlencode("TEST.xlsx"); 
    $this->response->header('Content-Disposition', $content);

    return $this->response;


Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.7 PHP 7.0.3 cakephp3.6


Answer questions ss-ikeda

I could download but the output xlsx looks broken... When opened the xlsx file, it asked if fix to see.

Github User Rank List