ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPExcel_Reader_CSV Class Reference
+ Inheritance diagram for PHPExcel_Reader_CSV:
+ Collaboration diagram for PHPExcel_Reader_CSV:

Public Member Functions

 __construct ()
 Create a new PHPExcel_Reader_CSV. More...
 
 setInputEncoding ($pValue='UTF-8')
 Set input encoding. More...
 
 getInputEncoding ()
 Get input encoding. More...
 
 listWorksheetInfo ($pFilename)
 Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) More...
 
 load ($pFilename)
 Loads PHPExcel from file. More...
 
 loadIntoExisting ($pFilename, PHPExcel $objPHPExcel)
 Loads PHPExcel from file into PHPExcel instance. More...
 
 getDelimiter ()
 Get delimiter. More...
 
 setDelimiter ($pValue=',')
 Set delimiter. More...
 
 getEnclosure ()
 Get enclosure. More...
 
 setEnclosure ($pValue='"')
 Set enclosure. More...
 
 getSheetIndex ()
 Get sheet index. More...
 
 setSheetIndex ($pValue=0)
 Set sheet index. More...
 
 setContiguous ($contiguous=FALSE)
 Set Contiguous. More...
 
 getContiguous ()
 Get Contiguous. More...
 
- Public Member Functions inherited from PHPExcel_Reader_Abstract
 getReadDataOnly ()
 Read data only? If this is true, then the Reader will only read data values for cells, it will not read any formatting information. More...
 
 setReadDataOnly ($pValue=FALSE)
 Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. More...
 
 getIncludeCharts ()
 Read charts in workbook? If this is true, then the Reader will include any charts that exist in the workbook. More...
 
 setIncludeCharts ($pValue=FALSE)
 Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook. More...
 
 getLoadSheetsOnly ()
 Get which sheets to load Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null indicating that all worksheets in the workbook should be loaded. More...
 
 setLoadSheetsOnly ($value=NULL)
 Set which sheets to load. More...
 
 setLoadAllSheets ()
 Set all sheets to load Tells the Reader to load all worksheets from the workbook. More...
 
 getReadFilter ()
 Read filter. More...
 
 setReadFilter (PHPExcel_Reader_IReadFilter $pValue)
 Set read filter. More...
 
 canRead ($pFilename)
 Can the current PHPExcel_Reader_IReader read the file? More...
 
 securityScan ($xml)
 Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks. More...
 
 securityScanFile ($filestream)
 Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks. More...
 
 canRead ($pFilename)
 Can the current PHPExcel_Reader_IReader read the file? More...
 
 load ($pFilename)
 

Protected Member Functions

 _isValidFormat ()
 Validate that the current file is a CSV file. More...
 
 _skipBOM ()
 Move filepointer past any BOM marker. More...
 
- Protected Member Functions inherited from PHPExcel_Reader_Abstract
 _openFile ($pFilename)
 Open file for reading. More...
 

Private Attributes

 $_inputEncoding = 'UTF-8'
 
 $_delimiter = ','
 
 $_enclosure = '"'
 
 $_sheetIndex = 0
 
 $_contiguous = false
 
 $_contiguousRow = -1
 

Additional Inherited Members

- Protected Attributes inherited from PHPExcel_Reader_Abstract
 $_readDataOnly = FALSE
 
 $_includeCharts = FALSE
 
 $_loadSheetsOnly = NULL
 
 $_readFilter = NULL
 
 $_fileHandle = NULL
 

Detailed Description

Definition at line 45 of file CSV.php.

Constructor & Destructor Documentation

◆ __construct()

PHPExcel_Reader_CSV::__construct ( )

Create a new PHPExcel_Reader_CSV.

Definition at line 98 of file CSV.php.

Member Function Documentation

◆ _isValidFormat()

PHPExcel_Reader_CSV::_isValidFormat ( )
protected

Validate that the current file is a CSV file.

Returns
boolean

Definition at line 107 of file CSV.php.

108 {
109 return TRUE;
110 }

Referenced by listWorksheetInfo(), and loadIntoExisting().

+ Here is the caller graph for this function:

◆ _skipBOM()

PHPExcel_Reader_CSV::_skipBOM ( )
protected

Move filepointer past any BOM marker.

Definition at line 137 of file CSV.php.

138 {
139 rewind($this->_fileHandle);
140
141 switch ($this->_inputEncoding) {
142 case 'UTF-8':
143 fgets($this->_fileHandle, 4) == "\xEF\xBB\xBF" ?
144 fseek($this->_fileHandle, 3) : fseek($this->_fileHandle, 0);
145 break;
146 case 'UTF-16LE':
147 fgets($this->_fileHandle, 3) == "\xFF\xFE" ?
148 fseek($this->_fileHandle, 2) : fseek($this->_fileHandle, 0);
149 break;
150 case 'UTF-16BE':
151 fgets($this->_fileHandle, 3) == "\xFE\xFF" ?
152 fseek($this->_fileHandle, 2) : fseek($this->_fileHandle, 0);
153 break;
154 case 'UTF-32LE':
155 fgets($this->_fileHandle, 5) == "\xFF\xFE\x00\x00" ?
156 fseek($this->_fileHandle, 4) : fseek($this->_fileHandle, 0);
157 break;
158 case 'UTF-32BE':
159 fgets($this->_fileHandle, 5) == "\x00\x00\xFE\xFF" ?
160 fseek($this->_fileHandle, 4) : fseek($this->_fileHandle, 0);
161 break;
162 default:
163 break;
164 }
165 }

Referenced by listWorksheetInfo(), and loadIntoExisting().

+ Here is the caller graph for this function:

◆ getContiguous()

PHPExcel_Reader_CSV::getContiguous ( )

Get Contiguous.

Returns
boolean

Definition at line 383 of file CSV.php.

383 {
384 return $this->_contiguous;
385 }

References $_contiguous.

◆ getDelimiter()

PHPExcel_Reader_CSV::getDelimiter ( )

Get delimiter.

Returns
string

Definition at line 305 of file CSV.php.

305 {
306 return $this->_delimiter;
307 }

References $_delimiter.

◆ getEnclosure()

PHPExcel_Reader_CSV::getEnclosure ( )

Get enclosure.

Returns
string

Definition at line 325 of file CSV.php.

325 {
326 return $this->_enclosure;
327 }

References $_enclosure.

◆ getInputEncoding()

PHPExcel_Reader_CSV::getInputEncoding ( )

Get input encoding.

Returns
string

Definition at line 128 of file CSV.php.

129 {
131 }

References $_inputEncoding.

◆ getSheetIndex()

PHPExcel_Reader_CSV::getSheetIndex ( )

Get sheet index.

Returns
integer

Definition at line 348 of file CSV.php.

348 {
349 return $this->_sheetIndex;
350 }

References $_sheetIndex.

◆ listWorksheetInfo()

PHPExcel_Reader_CSV::listWorksheetInfo (   $pFilename)

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

Parameters
string$pFilename
Exceptions
PHPExcel_Reader_Exception

Definition at line 173 of file CSV.php.

174 {
175 // Open file
176 $this->_openFile($pFilename);
177 if (!$this->_isValidFormat()) {
178 fclose ($this->_fileHandle);
179 throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
180 }
181 $fileHandle = $this->_fileHandle;
182
183 // Skip BOM, if any
184 $this->_skipBOM();
185
186 $escapeEnclosures = array( "\\" . $this->_enclosure, $this->_enclosure . $this->_enclosure );
187
188 $worksheetInfo = array();
189 $worksheetInfo[0]['worksheetName'] = 'Worksheet';
190 $worksheetInfo[0]['lastColumnLetter'] = 'A';
191 $worksheetInfo[0]['lastColumnIndex'] = 0;
192 $worksheetInfo[0]['totalRows'] = 0;
193 $worksheetInfo[0]['totalColumns'] = 0;
194
195 // Loop through each line of the file in turn
196 while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
197 $worksheetInfo[0]['totalRows']++;
198 $worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1);
199 }
200
201 $worksheetInfo[0]['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']);
202 $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;
203
204 // Close file
205 fclose($fileHandle);
206
207 return $worksheetInfo;
208 }
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
Definition: Cell.php:825
_openFile($pFilename)
Open file for reading.
Definition: Abstract.php:195
_isValidFormat()
Validate that the current file is a CSV file.
Definition: CSV.php:107
_skipBOM()
Move filepointer past any BOM marker.
Definition: CSV.php:137

References PHPExcel_Reader_Abstract\$_fileHandle, _isValidFormat(), PHPExcel_Reader_Abstract\_openFile(), _skipBOM(), and PHPExcel_Cell\stringFromColumnIndex().

+ Here is the call graph for this function:

◆ load()

PHPExcel_Reader_CSV::load (   $pFilename)

Loads PHPExcel from file.

Parameters
string$pFilename
Returns
PHPExcel
Exceptions
PHPExcel_Reader_Exception

Implements PHPExcel_Reader_IReader.

Definition at line 217 of file CSV.php.

218 {
219 // Create new PHPExcel
220 $objPHPExcel = new PHPExcel();
221
222 // Load into this instance
223 return $this->loadIntoExisting($pFilename, $objPHPExcel);
224 }
$objPHPExcel
loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
Loads PHPExcel from file into PHPExcel instance.
Definition: CSV.php:234

References $objPHPExcel, and loadIntoExisting().

+ Here is the call graph for this function:

◆ loadIntoExisting()

PHPExcel_Reader_CSV::loadIntoExisting (   $pFilename,
PHPExcel  $objPHPExcel 
)

Loads PHPExcel from file into PHPExcel instance.

Parameters
string$pFilename
PHPExcel$objPHPExcel
Returns
PHPExcel
Exceptions
PHPExcel_Reader_Exception

Definition at line 234 of file CSV.php.

235 {
236 $lineEnding = ini_get('auto_detect_line_endings');
237 ini_set('auto_detect_line_endings', true);
238
239 // Open file
240 $this->_openFile($pFilename);
241 if (!$this->_isValidFormat()) {
242 fclose ($this->_fileHandle);
243 throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
244 }
245 $fileHandle = $this->_fileHandle;
246
247 // Skip BOM, if any
248 $this->_skipBOM();
249
250 // Create new PHPExcel object
251 while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
252 $objPHPExcel->createSheet();
253 }
254 $sheet = $objPHPExcel->setActiveSheetIndex($this->_sheetIndex);
255
256 $escapeEnclosures = array( "\\" . $this->_enclosure,
257 $this->_enclosure . $this->_enclosure
258 );
259
260 // Set our starting row based on whether we're in contiguous mode or not
261 $currentRow = 1;
262 if ($this->_contiguous) {
263 $currentRow = ($this->_contiguousRow == -1) ? $sheet->getHighestRow(): $this->_contiguousRow;
264 }
265
266 // Loop through each line of the file in turn
267 while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
268 $columnLetter = 'A';
269 foreach($rowData as $rowDatum) {
270 if ($rowDatum != '' && $this->_readFilter->readCell($columnLetter, $currentRow)) {
271 // Unescape enclosures
272 $rowDatum = str_replace($escapeEnclosures, $this->_enclosure, $rowDatum);
273
274 // Convert encoding if necessary
275 if ($this->_inputEncoding !== 'UTF-8') {
276 $rowDatum = PHPExcel_Shared_String::ConvertEncoding($rowDatum, 'UTF-8', $this->_inputEncoding);
277 }
278
279 // Set cell value
280 $sheet->getCell($columnLetter . $currentRow)->setValue($rowDatum);
281 }
282 ++$columnLetter;
283 }
284 ++$currentRow;
285 }
286
287 // Close file
288 fclose($fileHandle);
289
290 if ($this->_contiguous) {
291 $this->_contiguousRow = $currentRow;
292 }
293
294 ini_set('auto_detect_line_endings', $lineEnding);
295
296 // Return
297 return $objPHPExcel;
298 }
static ConvertEncoding($value, $to, $from)
Convert string from one encoding to another.
Definition: String.php:493
getSheetCount()
Get sheet count.
Definition: PHPExcel.php:661

References $_contiguousRow, PHPExcel_Reader_Abstract\$_fileHandle, $objPHPExcel, _isValidFormat(), PHPExcel_Reader_Abstract\_openFile(), _skipBOM(), PHPExcel_Shared_String\ConvertEncoding(), and PHPExcel\getSheetCount().

Referenced by load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setContiguous()

PHPExcel_Reader_CSV::setContiguous (   $contiguous = FALSE)

Set Contiguous.

Parameters
boolean$contiguous

Definition at line 368 of file CSV.php.

369 {
370 $this->_contiguous = (bool) $contiguous;
371 if (!$contiguous) {
372 $this->_contiguousRow = -1;
373 }
374
375 return $this;
376 }

◆ setDelimiter()

PHPExcel_Reader_CSV::setDelimiter (   $pValue = ',')

Set delimiter.

Parameters
string$pValueDelimiter, defaults to ,
Returns
PHPExcel_Reader_CSV

Definition at line 315 of file CSV.php.

315 {
316 $this->_delimiter = $pValue;
317 return $this;
318 }

◆ setEnclosure()

PHPExcel_Reader_CSV::setEnclosure (   $pValue = '"')

Set enclosure.

Parameters
string$pValueEnclosure, defaults to "
Returns
PHPExcel_Reader_CSV

Definition at line 335 of file CSV.php.

335 {
336 if ($pValue == '') {
337 $pValue = '"';
338 }
339 $this->_enclosure = $pValue;
340 return $this;
341 }

◆ setInputEncoding()

PHPExcel_Reader_CSV::setInputEncoding (   $pValue = 'UTF-8')

Set input encoding.

Parameters
string$pValueInput encoding

Definition at line 117 of file CSV.php.

118 {
119 $this->_inputEncoding = $pValue;
120 return $this;
121 }

◆ setSheetIndex()

PHPExcel_Reader_CSV::setSheetIndex (   $pValue = 0)

Set sheet index.

Parameters
integer$pValueSheet index
Returns
PHPExcel_Reader_CSV

Definition at line 358 of file CSV.php.

358 {
359 $this->_sheetIndex = $pValue;
360 return $this;
361 }

Field Documentation

◆ $_contiguous

PHPExcel_Reader_CSV::$_contiguous = false
private

Definition at line 85 of file CSV.php.

Referenced by getContiguous().

◆ $_contiguousRow

PHPExcel_Reader_CSV::$_contiguousRow = -1
private

Definition at line 92 of file CSV.php.

Referenced by loadIntoExisting().

◆ $_delimiter

PHPExcel_Reader_CSV::$_delimiter = ','
private

Definition at line 61 of file CSV.php.

Referenced by getDelimiter().

◆ $_enclosure

PHPExcel_Reader_CSV::$_enclosure = '"'
private

Definition at line 69 of file CSV.php.

Referenced by getEnclosure().

◆ $_inputEncoding

PHPExcel_Reader_CSV::$_inputEncoding = 'UTF-8'
private

Definition at line 53 of file CSV.php.

Referenced by getInputEncoding().

◆ $_sheetIndex

PHPExcel_Reader_CSV::$_sheetIndex = 0
private

Definition at line 77 of file CSV.php.

Referenced by getSheetIndex().


The documentation for this class was generated from the following file: