-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Reusing a saved file which contained an image crashes #544
Comments
We need this feature to add data to an xls(x) file when its comes available, adding to the same file (open - add - save, wait days, repeat). Currently only works without an image. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This is still an issue. |
I cannot reproduce. The following code will write a new file with an image, reload it, and re-write to disk. The final will will be written correctly. <?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// Create new Spreadsheet object
$spreadsheet = new Spreadsheet();
// Generate an image
$gdImage = imagecreatetruecolor(250, 30);
$textColor = imagecolorallocate($gdImage, 255, 255, 255);
imagestring($gdImage, 4, 5, 5, 'Created with PhpSpreadsheet', $textColor);
// Add a drawing to the worksheet
$drawing = new MemoryDrawing();
$drawing->setImageResource($gdImage);
$drawing->setWorksheet($spreadsheet->getActiveSheet());
$writer = new Xlsx($spreadsheet);
$writer->save('test.xlsx');
$reloaded = IOFactory::load('test.xlsx');
$reloaded->getActiveSheet()->setCellValue('D5', 'foo');
$writer = new Xlsx($reloaded);
$writer->save('test2.xlsx'); Please re-open issue with a Minimal, Complete, and Verifiable example of code that exhibits this issue without relying on an external Excel file. |
After additional tests with l found that the error is caused when opening a file and saving it with the same filename:
The save will remove the original file causing the code to fail on reading the image. |
This is still an issue. A simple solution is to use a temp filename while saving and move it to the actual name at the end. |
Im getting same issue when using save('php://output'). Is there a work around for that? |
This is:
What is the expected behavior?
A spreadsheet should be saved and opened multiple times, even if it contains images.
What is the current behavior?
When opening and saving the file again, after it was saved, the following PHP error is generated:
What are the steps to reproduce?
Start a new document with Excel 2016 insert a small PNG image and save the document.
Upload it to webserver.
Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:
Which versions of PhpSpreadsheet and PHP are affected?
Just downloaded the lastest version here.
PHP version 7.0.23
The text was updated successfully, but these errors were encountered: