profile
viewpoint

Ask questionsUnreadable content when including drawings

This is:

  • [x] a bug report (I beleive)

What is the expected behavior?

Include drawings without causing any problems

What is the current behavior?

If I add drawings dynamically (via code) this causes an "unreadable content" message when opening the file. The odd thing is that this is only happening on my local webserver, not online (!).

What are the steps to reproduce?

I simply added

$drawing = new PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setPath(__DIR__ . '/assets/img/logodefViola.png'); 
$drawing->setHeight(40);
$drawing->setCoordinates('B1');  
$drawing->setWorksheet($spreadsheet->getActiveSheet()); 

Which versions of PhpSpreadsheet and PHP are affected?

I downloaded it one week ago then I guess it's the most up to date

I commented another issue (https://github.com/PHPOffice/PhpSpreadsheet/issues/610) but then I realized it is closed for some reason, even if it is not solved:

This is the story: When I "clone" a worksheet that includes a drawing (I have a logo on each worksheet ) the response is an "out of memory". Then as a workaround I decided to make a template without logo and use the

$drawing = new PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setPath(__DIR__ . '/assets/img/logodefViola.png'); 
$drawing->setHeight(40);
$drawing->setCoordinates('B1');  
$drawing->setWorksheet($spreadsheet->getActiveSheet()); 

to include the logo dinamically everytime I clone a worksheet. This seems to work BUT, probably linked to this, I have another issue which might be a character coding issue but can't find how to solve it: when I generate my excel file on localhost it says there is unreadable text in the file (I have tried the exit() instruction at the end of the file, I have tried to remove the '?>' chars, as I found in another thread...still this is the error I see) and then another mask appears where it says PRINTER OPTIONS are REMOVED, which is what I don't want: I need print options (on A3 paper and front/rear ) to be saved and replicated on all worksheets I generate, not removed.... I tried to publish online ad happily I have no more "unreadable character", but I need it to work locally too, to make my tests....what do you suggest me to try? Find attached screenshot: they're in italian I make some translation for you : ) screenshot 2019-02-05 16 56 03 (translation: ...".xlsx includes unreadable content. Recover worksheet content?) screenshot 2019-02-05 16 56 11 (translation: the file could be recovered : it is possible that some parts got deleted: Print options Print options Print options ...etc: most likely one per each worksheet I cloned... Please help

If I remove the "drawings" part everything works fine.

[To give more details that might help: I have another issue in my application that might be connected to the above problem: character coding is not the same locally and on the web and even though I have tried to solve this in 1000 ways (editing httpd.conf, editing php.ini, adding meta tags on my html pages) still I see my texts locally not displayed in the right way...all accented letters are mistyped....which is not happening online.]

Please help

PHPOffice/PhpSpreadsheet

Answer questions githubjeka

Confirmed. Any images of template dont transfer to new XLSX. Any new images dont insert if template XLSX have images. This depends by this code https://github.com/PHPOffice/PhpSpreadsheet/blob/ebc0b5695912e67545e0442ee3df0c044eac066b/src/PhpSpreadsheet/Writer/Xlsx.php#L331-L340

The path xl\drawings\drawing1.xml created with your new images before this code. But this code replace path xl\drawings\drawing1.xml to original from template. Also path xl\drawings\_rels has incorect data

useful!
source:https://uonfu.com/
answerer
Evgeniy Tkachenko githubjeka Belarus When one man, for whatever reason, has the opportunity to lead an extraordinary life, he has no right to keep it to himself.
Github User Rank List