30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
130 if (!file_exists($pFilename)) {
131 throw new Exception(
"Could not open " . $pFilename .
" for reading! File does not exist.");
145 public function load($pFilename)
171 $this->_readFilter = $pValue;
183 $this->_inputEncoding = $pValue;
210 if (!file_exists($pFilename)) {
211 throw new Exception(
"Could not open " . $pFilename .
" for reading! File does not exist.");
221 $fileHandle = fopen($pFilename,
'r');
222 if ($fileHandle ===
false) {
223 throw new Exception(
"Could not open file $pFilename for reading.");
227 switch ($this->_inputEncoding) {
229 fgets($fileHandle, 4) ==
"\xEF\xBB\xBF" ?
230 fseek($fileHandle, 3) : fseek($fileHandle, 0);
233 fgets($fileHandle, 3) ==
"\xFF\xFE" ?
234 fseek($fileHandle, 2) : fseek($fileHandle, 0);
237 fgets($fileHandle, 3) ==
"\xFE\xFF" ?
238 fseek($fileHandle, 2) : fseek($fileHandle, 0);
241 fgets($fileHandle, 5) ==
"\xFF\xFE\x00\x00" ?
242 fseek($fileHandle, 4) : fseek($fileHandle, 0);
245 fgets($fileHandle, 5) ==
"\x00\x00\xFE\xFF" ?
246 fseek($fileHandle, 4) : fseek($fileHandle, 0);
252 $escapeEnclosures = array(
"\\" . $this->_enclosure,
253 $this->_enclosure . $this->_enclosure
258 if ($this->_contiguous) {
263 while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
265 foreach($rowData as $rowDatum) {
266 if ($rowDatum !=
'' && $this->_readFilter->readCell($columnLetter, $currentRow)) {
268 $rowDatum = str_replace($escapeEnclosures, $this->_enclosure, $rowDatum);
271 if ($this->_inputEncoding !==
'UTF-8') {
276 $objPHPExcel->
getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowDatum);
286 if ($this->_contiguous) {
287 $this->_contiguousRow = $currentRow;
312 $this->_delimiter = $pValue;
337 $this->_enclosure = $pValue;
359 $this->_lineEnding = $pValue;
381 $this->_sheetIndex = $pValue;
393 $this->_contiguous = (bool)$contiguous;
395 $this->_contiguousRow = -1;