profile
viewpoint

Ask questionsCorrupt XLSX file when drawing image

This is:

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

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');
    $spreadsheet->setActiveSheetIndex(0);
    $sheet = $spreadsheet->getActiveSheet();

    //add image in excel
    $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
    $drawing->setName('Logo');
    $drawing->setDescription('Logo');
    $drawing->setPath(WWW_ROOT."docs/C20101Docs/20190404202343.png"); 
    $drawing->setCoordinates('A1');
    $drawing->setWorksheet($sheet);
    unset($drawing);

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

    $content = 'attachment;';
    $content .= 'filename*=UTF-8\'\''.rawurlencode("TEST.xlsx"); 
    $this->response->header('Content-Disposition', $content);
    $this->response->type('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    $this->response->file($tmp_path);

    return $this->response;
}

}

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.7 PHP 7.0.3 cakephp3.6

PHPOffice/PhpSpreadsheet

Answer questions ss-ikeda

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

useful!
source:https://uonfu.com/
Github User Rank List