public function PHPExcel_Reader_CSV::loadIntoExisting in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/CSV.php \PHPExcel_Reader_CSV::loadIntoExisting()
* Loads PHPExcel from file into PHPExcel instance * *
Parameters
string $pFilename: * @param PHPExcel $objPHPExcel * @return PHPExcel * @throws PHPExcel_Reader_Exception
1 call to PHPExcel_Reader_CSV::loadIntoExisting()
- PHPExcel_Reader_CSV::load in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Reader/ CSV.php - * Loads PHPExcel from file * *
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Reader/ CSV.php, line 234
Class
- PHPExcel_Reader_CSV
- PHPExcel_Reader_CSV
Code
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) {
$lineEnding = ini_get('auto_detect_line_endings');
ini_set('auto_detect_line_endings', true);
// 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();
// Create new PHPExcel object
while ($objPHPExcel
->getSheetCount() <= $this->_sheetIndex) {
$objPHPExcel
->createSheet();
}
$sheet = $objPHPExcel
->setActiveSheetIndex($this->_sheetIndex);
$escapeEnclosures = array(
"\\" . $this->_enclosure,
$this->_enclosure . $this->_enclosure,
);
// Set our starting row based on whether we're in contiguous mode or not
$currentRow = 1;
if ($this->_contiguous) {
$currentRow = $this->_contiguousRow == -1 ? $sheet
->getHighestRow() : $this->_contiguousRow;
}
// Loop through each line of the file in turn
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
$columnLetter = 'A';
foreach ($rowData as $rowDatum) {
if ($rowDatum != '' && $this->_readFilter
->readCell($columnLetter, $currentRow)) {
// Unescape enclosures
$rowDatum = str_replace($escapeEnclosures, $this->_enclosure, $rowDatum);
// Convert encoding if necessary
if ($this->_inputEncoding !== 'UTF-8') {
$rowDatum = PHPExcel_Shared_String::ConvertEncoding($rowDatum, 'UTF-8', $this->_inputEncoding);
}
// Set cell value
$sheet
->getCell($columnLetter . $currentRow)
->setValue($rowDatum);
}
++$columnLetter;
}
++$currentRow;
}
// Close file
fclose($fileHandle);
if ($this->_contiguous) {
$this->_contiguousRow = $currentRow;
}
ini_set('auto_detect_line_endings', $lineEnding);
// Return
return $objPHPExcel;
}