You are here

public function PHPExcel_Writer_HTML::generateSheetData in Loft Data Grids 6.2

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

* Generate sheet data * *

Return value

string * @throws PHPExcel_Writer_Exception

4 calls to PHPExcel_Writer_HTML::generateSheetData()
PHPExcel_Writer_HTML::save in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php
* Save PHPExcel to file * *
PHPExcel_Writer_PDF_DomPDF::save in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/PDF/DomPDF.php
Save PHPExcel to file
PHPExcel_Writer_PDF_mPDF::save in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/PDF/mPDF.php
Save PHPExcel to file
PHPExcel_Writer_PDF_tcPDF::save in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/PDF/tcPDF.php
Save PHPExcel to file

File

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

Class

PHPExcel_Writer_HTML
PHPExcel_Writer_HTML

Code

public function generateSheetData() {

  // PHPExcel object known?
  if (is_null($this->_phpExcel)) {
    throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
  }

  // Ensure that Spans have been calculated?
  if (!$this->_spansAreCalculated) {
    $this
      ->_calculateSpans();
  }

  // Fetch sheets
  $sheets = array();
  if (is_null($this->_sheetIndex)) {
    $sheets = $this->_phpExcel
      ->getAllSheets();
  }
  else {
    $sheets[] = $this->_phpExcel
      ->getSheet($this->_sheetIndex);
  }

  // Construct HTML
  $html = '';

  // Loop all sheets
  $sheetId = 0;
  foreach ($sheets as $sheet) {

    // Write table header
    $html .= $this
      ->_generateTableHeader($sheet);

    // Get worksheet dimension
    $dimension = explode(':', $sheet
      ->calculateWorksheetDimension());
    $dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
    $dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
    $dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
    $dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;

    // row min,max
    $rowMin = $dimension[0][1];
    $rowMax = $dimension[1][1];

    // calculate start of <tbody>, <thead>
    $tbodyStart = $rowMin;
    $theadStart = $theadEnd = 0;

    // default: no <thead>	no </thead>
    if ($sheet
      ->getPageSetup()
      ->isRowsToRepeatAtTopSet()) {
      $rowsToRepeatAtTop = $sheet
        ->getPageSetup()
        ->getRowsToRepeatAtTop();

      // we can only support repeating rows that start at top row
      if ($rowsToRepeatAtTop[0] == 1) {
        $theadStart = $rowsToRepeatAtTop[0];
        $theadEnd = $rowsToRepeatAtTop[1];
        $tbodyStart = $rowsToRepeatAtTop[1] + 1;
      }
    }

    // Loop through cells
    $row = $rowMin - 1;
    while ($row++ < $rowMax) {

      // <thead> ?
      if ($row == $theadStart) {
        $html .= '		<thead>' . PHP_EOL;
        $cellType = 'th';
      }

      // <tbody> ?
      if ($row == $tbodyStart) {
        $html .= '		<tbody>' . PHP_EOL;
        $cellType = 'td';
      }

      // Write row if there are HTML table cells in it
      if (!isset($this->_isSpannedRow[$sheet
        ->getParent()
        ->getIndex($sheet)][$row])) {

        // Start a new rowData
        $rowData = array();

        // Loop through columns
        $column = $dimension[0][0] - 1;
        while ($column++ < $dimension[1][0]) {

          // Cell exists?
          if ($sheet
            ->cellExistsByColumnAndRow($column, $row)) {
            $rowData[$column] = PHPExcel_Cell::stringFromColumnIndex($column) . $row;
          }
          else {
            $rowData[$column] = '';
          }
        }
        $html .= $this
          ->_generateRow($sheet, $rowData, $row - 1, $cellType);
      }

      // </thead> ?
      if ($row == $theadEnd) {
        $html .= '		</thead>' . PHP_EOL;
      }
    }
    $html .= $this
      ->_extendRowsForChartsAndImages($sheet, $row);

    // Close table body.
    $html .= '		</tbody>' . PHP_EOL;

    // Write table footer
    $html .= $this
      ->_generateTableFooter();

    // Writing PDF?
    if ($this->_isPdf) {
      if (is_null($this->_sheetIndex) && $sheetId + 1 < $this->_phpExcel
        ->getSheetCount()) {
        $html .= '<div style="page-break-before:always" />';
      }
    }

    // Next sheet
    ++$sheetId;
  }

  // Return
  return $html;
}