';
for ($col = 'A'; $col != $colMax; ++$col) {
- $html .= '';
- $html .= $this->writeImageInCell($pSheet, $col . $row);
- if ($this->includeCharts) {
- $html .= $this->writeChartInCell($pSheet, $col . $row);
+ $htmlx = $this->writeImageInCell($pSheet, $col . $row);
+ $htmlx .= $this->includeCharts ? $this->writeChartInCell($pSheet, $col . $row) : '';
+ if ($htmlx) {
+ $html .= " | $htmlx | ";
+ } else {
+ $html .= " | ";
}
- $html .= '';
}
++$row;
- $html .= '
';
+ $html .= '' . PHP_EOL;
}
return $html;
}
+ /**
+ * Convert Windows file name to file protocol URL.
+ *
+ * @param string $filename file name on local system
+ *
+ * @return string
+ */
+ public static function winFileToUrl($filename)
+ {
+ // Windows filename
+ if (substr($filename, 1, 2) === ':\\') {
+ $filename = 'file:///' . str_replace('\\', '/', $filename);
+ }
+
+ return $filename;
+ }
+
/**
* Generate image tag in cell.
*
@@ -613,57 +636,44 @@ class Html extends BaseWriter
// Write images
foreach ($pSheet->getDrawingCollection() as $drawing) {
+ if ($drawing->getCoordinates() != $coordinates) {
+ continue;
+ }
+ $filedesc = $drawing->getDescription();
+ $filedesc = $filedesc ? htmlspecialchars($filedesc, ENT_QUOTES) : 'Embedded image';
if ($drawing instanceof Drawing) {
- if ($drawing->getCoordinates() == $coordinates) {
- $filename = $drawing->getPath();
+ $filename = $drawing->getPath();
- // Strip off eventual '.'
- if (substr($filename, 0, 1) == '.') {
- $filename = substr($filename, 1);
- }
+ // Strip off eventual '.'
+ $filename = preg_replace('/^[.]/', '', $filename);
- // Prepend images root
- $filename = $this->getImagesRoot() . $filename;
+ // Prepend images root
+ $filename = $this->getImagesRoot() . $filename;
- // Strip off eventual '.'
- if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') {
- $filename = substr($filename, 1);
- }
+ // Strip off eventual '.' if followed by non-/
+ $filename = preg_replace('@^[.]([^/])@', '$1', $filename);
- // Convert UTF8 data to PCDATA
- $filename = htmlspecialchars($filename);
+ // Convert UTF8 data to PCDATA
+ $filename = htmlspecialchars($filename);
- $html .= PHP_EOL;
- if ((!$this->embedImages) || ($this->isPdf)) {
- $imageData = $filename;
- } else {
+ $html .= PHP_EOL;
+ $imageData = self::winFileToUrl($filename);
+
+ if ($this->embedImages && !$this->isPdf) {
+ $picture = @file_get_contents($filename);
+ if ($picture !== false) {
$imageDetails = getimagesize($filename);
- if ($fp = fopen($filename, 'rb', 0)) {
- $picture = '';
- while (!feof($fp)) {
- $picture .= fread($fp, 1024);
- }
- fclose($fp);
- // base64 encode the binary data, then break it
- // into chunks according to RFC 2045 semantics
- $base64 = chunk_split(base64_encode($picture));
- $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;
- } else {
- $imageData = $filename;
- }
+ // base64 encode the binary data
+ $base64 = base64_encode($picture);
+ $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;
}
+ }
- $html .= '