You are here

private function PHPExcel_Writer_HTML::_writeChartInCell in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php \PHPExcel_Writer_HTML::_writeChartInCell()

* Generate chart tag in cell * *

Parameters

PHPExcel_Worksheet $pSheet PHPExcel_Worksheet: * @param string $coordinates Cell coordinates * @return string * @throws PHPExcel_Writer_Exception

2 calls to PHPExcel_Writer_HTML::_writeChartInCell()
PHPExcel_Writer_HTML::_extendRowsForChartsAndImages in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php
PHPExcel_Writer_HTML::_generateRow in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php
* Generate row * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php, line 634

Class

PHPExcel_Writer_HTML
PHPExcel_Writer_HTML

Code

private function _writeChartInCell(PHPExcel_Worksheet $pSheet, $coordinates) {

  // Construct HTML
  $html = '';

  // Write charts
  foreach ($pSheet
    ->getChartCollection() as $chart) {
    if ($chart instanceof PHPExcel_Chart) {
      $chartCoordinates = $chart
        ->getTopLeftPosition();
      if ($chartCoordinates['cell'] == $coordinates) {
        $chartFileName = PHPExcel_Shared_File::sys_get_temp_dir() . '/' . uniqid() . '.png';
        if (!$chart
          ->render($chartFileName)) {
          return;
        }
        $html .= PHP_EOL;
        $imageDetails = getimagesize($chartFileName);
        if ($fp = fopen($chartFileName, "rb", 0)) {
          $picture = fread($fp, filesize($chartFileName));
          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;
          $html .= '<div style="position: relative;">';
          $html .= '<img style="position: absolute; z-index: 1; left: ' . $chartCoordinates['xOffset'] . 'px; top: ' . $chartCoordinates['yOffset'] . 'px; width: ' . $imageDetails[0] . 'px; height: ' . $imageDetails[1] . 'px;" src="' . $imageData . '" border="0" />' . PHP_EOL;
          $html .= '</div>';
          unlink($chartFileName);
        }
      }
    }
  }

  // Return
  return $html;
}