Feature: (Tomino2112) Work Item GH-808 - MemoryDrawing not working in HTML writer

Manual merge of Pull Request
This commit is contained in:
MarkBaker 2016-03-01 23:16:13 +00:00
parent fa98c373df
commit 4a67f086a1
3 changed files with 25 additions and 1 deletions

View File

@ -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') , " 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 memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
// Echo done // Echo done
echo date('H:i:s') , " Done writing file" , EOL; 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;

View File

@ -30,6 +30,8 @@ Planned for 1.9
- General: (umpirsky) Work Item GH-548 - Optimize vlookup() sort - General: (umpirsky) Work Item GH-548 - Optimize vlookup() sort
- Feature: (MBaker) - Initial implementation of SUMIFS() function - Feature: (MBaker) - Initial implementation of SUMIFS() function
- Feature: (MBaker) - Additional codepages - Feature: (MBaker) - Additional codepages
- Feature: (Tomino2112) Work Item GH-808 - MemoryDrawing not working in HTML writer
2015-04-30 (v1.8.1): 2015-04-30 (v1.8.1):
- Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula - Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula

View File

@ -655,6 +655,22 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
$imageData . '" border="0" />'; $imageData . '" border="0" />';
$html .= '</div>'; $html .= '</div>';
} }
} 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 .= '<img src="'.$dataUri.'" style="max-width:100%;width:'.$drawing->getWidth().'px;" />';
} }
} }