PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

The problem that the shape and image of a specific sheet disappear when saving a file

Open jongba opened this issue 3 years ago • 10 comments

<?php

require __DIR__ . '/vendor/autoload.php';

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($origin_file);

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->setPreCalculateFormulas(false);
$writer->setOffice2003Compatibility(true);
$new_file = './file_uploads/report_file/' . $file_info_idx.'_tmp.'.$file_ext;
$writer->save($new_file);
  • original file

image

  • write new file

image

As above, if you save a picture or image of a specific sheet in the original file as a new file, the picture or image will be lost. ex) sheet2

Is there something I'm missing out on?

jongba avatar Feb 24 '22 11:02 jongba

Please upload the original file.

oleibman avatar Feb 24 '22 15:02 oleibman

1046.xlsx

For security reasons, we will remove all contents.

Please check the parts where figures and images are missing.

jongba avatar Feb 25 '22 00:02 jongba

Thank you for the file. I can confirm your problem. The images that are missing all seem to be "shapes" rather than "drawings", but not all shapes are missing (e.g. on sheet 2). I don't know anything about shape files, except that they have been involved in other issues. It could take a while to figure out what is happening, and what should be happening instead.

oleibman avatar Feb 25 '22 04:02 oleibman

Only certain shapes are kept and the rest of the shapes are lost. What code should I write to keep it?

beomheechoi avatar Feb 25 '22 04:02 beomheechoi

I don't think the problem is in your code. I think the problem can be solved only by better handling of shape files by PhpSpreadsheet, which I think will not be a quick or easy change.

oleibman avatar Feb 25 '22 05:02 oleibman

Correct; shape files aren't supported at all by PhpSpreadsheet; we'd have to build that support from the basics upwards

MarkBaker avatar Feb 25 '22 08:02 MarkBaker

So what should we do?

please tell me how

jongba avatar Feb 25 '22 08:02 jongba

You live with it until we can implement it; or work out how to implement it yourself and submit a PR

MarkBaker avatar Feb 25 '22 20:02 MarkBaker

@MarkBaker is there any solution for this problem, i also experienced it, my shape is missing

rikikuswo avatar Apr 04 '22 03:04 rikikuswo

drawing or shape is removed ☹️

edit i fixed it by ungrouping everything in the worksheet

ikibiki avatar Sep 30 '22 08:09 ikibiki