You are here

public function PHPExcel_Reader_CSV::listWorksheetInfo in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/CSV.php \PHPExcel_Reader_CSV::listWorksheetInfo()

* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * *

Parameters

string $pFilename: * @throws PHPExcel_Reader_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/CSV.php, line 173

Class

PHPExcel_Reader_CSV
PHPExcel_Reader_CSV

Code

public function listWorksheetInfo($pFilename) {

  // Open file
  $this
    ->_openFile($pFilename);
  if (!$this
    ->_isValidFormat()) {
    fclose($this->_fileHandle);
    throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
  }
  $fileHandle = $this->_fileHandle;

  // Skip BOM, if any
  $this
    ->_skipBOM();
  $escapeEnclosures = array(
    "\\" . $this->_enclosure,
    $this->_enclosure . $this->_enclosure,
  );
  $worksheetInfo = array();
  $worksheetInfo[0]['worksheetName'] = 'Worksheet';
  $worksheetInfo[0]['lastColumnLetter'] = 'A';
  $worksheetInfo[0]['lastColumnIndex'] = 0;
  $worksheetInfo[0]['totalRows'] = 0;
  $worksheetInfo[0]['totalColumns'] = 0;

  // Loop through each line of the file in turn
  while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
    $worksheetInfo[0]['totalRows']++;
    $worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1);
  }
  $worksheetInfo[0]['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']);
  $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;

  // Close file
  fclose($fileHandle);
  return $worksheetInfo;
}