From 4a67f086a104124b39f021a25dc8fb86fad11fe2 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 1 Mar 2016 23:16:13 +0000 Subject: [PATCH] Feature: (Tomino2112) Work Item GH-808 - MemoryDrawing not working in HTML writer Manual merge of Pull Request --- Examples/25inmemoryimage.php | 8 +++++++- changelog.txt | 2 ++ src/PhpSpreadsheet/Writer/HTML.php | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Examples/25inmemoryimage.php b/Examples/25inmemoryimage.php index 167a861a..6c3b0b84 100644 --- a/Examples/25inmemoryimage.php +++ b/Examples/25inmemoryimage.php @@ -75,9 +75,15 @@ $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo date('H:i:s') , " Write to HTML format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML'); +$objWriter->save(str_replace('.php', '.html', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.html', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + // Echo memory peak usage echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; // Echo done echo date('H:i:s') , " Done writing file" , EOL; -echo 'File has been created in ' , getcwd() , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/changelog.txt b/changelog.txt index dbf9cfda..ba5d10bc 100644 --- a/changelog.txt +++ b/changelog.txt @@ -30,6 +30,8 @@ Planned for 1.9 - General: (umpirsky) Work Item GH-548 - Optimize vlookup() sort - Feature: (MBaker) - Initial implementation of SUMIFS() function - Feature: (MBaker) - Additional codepages +- Feature: (Tomino2112) Work Item GH-808 - MemoryDrawing not working in HTML writer + 2015-04-30 (v1.8.1): - Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula diff --git a/src/PhpSpreadsheet/Writer/HTML.php b/src/PhpSpreadsheet/Writer/HTML.php index ee8420e2..1b15d915 100644 --- a/src/PhpSpreadsheet/Writer/HTML.php +++ b/src/PhpSpreadsheet/Writer/HTML.php @@ -655,6 +655,22 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_ $imageData . '" border="0" />'; $html .= ''; } + } elseif ($drawing instanceof \PHPExcel\Worksheet\MemoryDrawing) { + if ($drawing->getCoordinates() != $coordinates) { + continue; + } + ob_start(); // Let's start output buffering. + imagepng($drawing->getImageResource()); // This will normally output the image, but because of ob_start(), it won't. + $contents = ob_get_contents(); // Instead, output above is saved to $contents + ob_end_clean(); // End the output buffer. + + $dataUri = "data:image/jpeg;base64," . base64_encode($contents); + + // Because of the nature of tables, width is more important than height. + // max-width: 100% ensures that image doesnt overflow containing cell + // width: X sets width of supplied image. + // As a result, images bigger than cell will be contained and images smaller will not get stretched + $html .= ''; } }