ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 canRead ($pFilename)
 Can the current PHPExcel_Reader_IReader read the file?
 load ($pFilename)
 Loads PHPExcel from file.
 getReadFilter ()
 Read filter.
 setReadFilter (PHPExcel_Reader_IReadFilter $pValue)
 Set read filter.
 loadIntoExisting ($pFilename, PHPExcel $objPHPExcel)
 Loads PHPExcel from file into PHPExcel instance.
 getDelimiter ()
 Get delimiter.
 setDelimiter ($pValue= ',')
 Set delimiter.
 getEnclosure ()
 Get enclosure.
 setEnclosure ($pValue= '"')
 Set enclosure.
 getLineEnding ()
 Get line ending.
 setLineEnding ($pValue=PHP_EOL)
 Set line ending.
 getSheetIndex ()
 Get sheet index.
 setSheetIndex ($pValue=0)
 Set sheet index.

Private Attributes

 $_delimiter
 $_enclosure
 $_lineEnding
 $_sheetIndex
 $_readFilter = null

Detailed Description

Definition at line 60 of file CSV.php.

Constructor & Destructor Documentation

PHPExcel_Reader_CSV::__construct ( )

Create a new PHPExcel_Reader_CSV.

Definition at line 100 of file CSV.php.

{
$this->_delimiter = ',';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}

Member Function Documentation

PHPExcel_Reader_CSV::canRead (   $pFilename)

Can the current PHPExcel_Reader_IReader read the file?

Parameters
string$pFileName
Returns
boolean

Implements PHPExcel_Reader_IReader.

Definition at line 114 of file CSV.php.

{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Check if it is a CSV file (using file name)
return (substr(strtolower($pFilename), -3) == 'csv');
}
PHPExcel_Reader_CSV::getDelimiter ( )

Get delimiter.

Returns
string

Definition at line 217 of file CSV.php.

References $_delimiter.

{
}
PHPExcel_Reader_CSV::getEnclosure ( )

Get enclosure.

Returns
string

Definition at line 237 of file CSV.php.

References $_enclosure.

{
}
PHPExcel_Reader_CSV::getLineEnding ( )

Get line ending.

Returns
string

Definition at line 260 of file CSV.php.

References $_lineEnding.

{
}
PHPExcel_Reader_CSV::getReadFilter ( )

Read filter.

Returns
PHPExcel_Reader_IReadFilter

Definition at line 145 of file CSV.php.

References $_readFilter.

{
}
PHPExcel_Reader_CSV::getSheetIndex ( )

Get sheet index.

Returns
int

Definition at line 280 of file CSV.php.

References $_sheetIndex.

{
}
PHPExcel_Reader_CSV::load (   $pFilename)

Loads PHPExcel from file.

Parameters
string$pFilename
Exceptions
Exception

Implements PHPExcel_Reader_IReader.

Definition at line 131 of file CSV.php.

References loadIntoExisting().

{
// Create new PHPExcel
$objPHPExcel = new PHPExcel();
// Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}

+ Here is the call graph for this function:

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

Loads PHPExcel from file into PHPExcel instance.

Parameters
string$pFilename
PHPExcel$objPHPExcel
Exceptions
Exception

Definition at line 165 of file CSV.php.

References $_sheetIndex, PHPExcel\createSheet(), PHPExcel\getActiveSheet(), PHPExcel\getSheetCount(), PHPExcel\setActiveSheetIndex(), and PHPExcel_Cell\stringFromColumnIndex().

Referenced by load().

{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Create new PHPExcel
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
$objPHPExcel->createSheet();
}
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex );
// Open file
$fileHandle = fopen($pFilename, 'r');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for reading.");
}
// Loop trough file
$currentRow = 0;
$rowData = array();
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
++$currentRow;
$rowDataCount = count($rowData);
for ($i = 0; $i < $rowDataCount; ++$i) {
if ($rowData[$i] != '' && $this->_readFilter->readCell($columnLetter, $currentRow)) {
// Unescape enclosures
$rowData[$i] = str_replace("\\" . $this->_enclosure, $this->_enclosure, $rowData[$i]);
$rowData[$i] = str_replace($this->_enclosure . $this->_enclosure, $this->_enclosure, $rowData[$i]);
// Set cell value
$objPHPExcel->getActiveSheet()->setCellValue(
$columnLetter . $currentRow, $rowData[$i]
);
}
}
}
// Close file
fclose($fileHandle);
// Return
return $objPHPExcel;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Set delimiter.

Parameters
string$pValueDelimiter, defaults to ,
Returns
PHPExcel_Reader_CSV

Definition at line 227 of file CSV.php.

{
$this->_delimiter = $pValue;
return $this;
}
PHPExcel_Reader_CSV::setEnclosure (   $pValue = '"')

Set enclosure.

Parameters
string$pValueEnclosure, defaults to "
Returns
PHPExcel_Reader_CSV

Definition at line 247 of file CSV.php.

{
if ($pValue == '') {
$pValue = '"';
}
$this->_enclosure = $pValue;
return $this;
}
PHPExcel_Reader_CSV::setLineEnding (   $pValue = PHP_EOL)

Set line ending.

Parameters
string$pValueLine ending, defaults to OS line ending (PHP_EOL)
Returns
PHPExcel_Reader_CSV

Definition at line 270 of file CSV.php.

{
$this->_lineEnding = $pValue;
return $this;
}
PHPExcel_Reader_CSV::setReadFilter ( PHPExcel_Reader_IReadFilter  $pValue)

Set read filter.

Parameters
PHPExcel_Reader_IReadFilter$pValue

Definition at line 154 of file CSV.php.

{
$this->_readFilter = $pValue;
}
PHPExcel_Reader_CSV::setSheetIndex (   $pValue = 0)

Set sheet index.

Parameters
int$pValueSheet index
Returns
PHPExcel_Reader_CSV

Definition at line 290 of file CSV.php.

{
$this->_sheetIndex = $pValue;
return $this;
}

Field Documentation

PHPExcel_Reader_CSV::$_delimiter
private

Definition at line 67 of file CSV.php.

Referenced by getDelimiter().

PHPExcel_Reader_CSV::$_enclosure
private

Definition at line 74 of file CSV.php.

Referenced by getEnclosure().

PHPExcel_Reader_CSV::$_lineEnding
private

Definition at line 81 of file CSV.php.

Referenced by getLineEnding().

PHPExcel_Reader_CSV::$_readFilter = null
private

Definition at line 95 of file CSV.php.

Referenced by getReadFilter().

PHPExcel_Reader_CSV::$_sheetIndex
private

Definition at line 88 of file CSV.php.

Referenced by getSheetIndex(), and loadIntoExisting().


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