ILIAS  eassessment Revision 61809
 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.
 setInputEncoding ($pValue= 'UTF-8')
 Set input encoding.
 getInputEncoding ()
 Get input encoding.
 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.
 setContiguous ($contiguous=false)
 Set Contiguous.
 getContiguous ()
 Get Contiguous.

Private Attributes

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

Detailed Description

Definition at line 45 of file CSV.php.

Constructor & Destructor Documentation

PHPExcel_Reader_CSV::__construct ( )

Create a new PHPExcel_Reader_CSV.

Definition at line 115 of file CSV.php.

{
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
} // function __construct()

Member Function Documentation

PHPExcel_Reader_CSV::canRead (   $pFilename)

Can the current PHPExcel_Reader_IReader read the file?

public

Parameters
string$pFileName
Returns
boolean
Exceptions
Exception

Implements PHPExcel_Reader_IReader.

Definition at line 127 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.");
}
return true;
} // function canRead()
PHPExcel_Reader_CSV::getContiguous ( )

Get Contiguous.

public

Returns
boolean

Definition at line 407 of file CSV.php.

References $_contiguous.

{
} // function getSheetIndex()
PHPExcel_Reader_CSV::getDelimiter ( )

Get delimiter.

public

Returns
string

Definition at line 300 of file CSV.php.

References $_delimiter.

{
} // function getDelimiter()
PHPExcel_Reader_CSV::getEnclosure ( )

Get enclosure.

public

Returns
string

Definition at line 322 of file CSV.php.

References $_enclosure.

{
} // function getEnclosure()
PHPExcel_Reader_CSV::getInputEncoding ( )

Get input encoding.

public

Returns
string

Definition at line 193 of file CSV.php.

References $_inputEncoding.

{
} // function getInputEncoding()
PHPExcel_Reader_CSV::getLineEnding ( )

Get line ending.

public

Returns
string

Definition at line 347 of file CSV.php.

References $_lineEnding.

{
} // function getLineEnding()
PHPExcel_Reader_CSV::getReadFilter ( )

Read filter.

public

Returns
PHPExcel_Reader_IReadFilter

Definition at line 160 of file CSV.php.

References $_readFilter.

{
} // function getReadFilter()
PHPExcel_Reader_CSV::getSheetIndex ( )

Get sheet index.

public

Returns
int

Definition at line 369 of file CSV.php.

References $_sheetIndex.

{
} // function getSheetIndex()
PHPExcel_Reader_CSV::load (   $pFilename)

Loads PHPExcel from file.

public

Parameters
string$pFilename
Returns
PHPExcel
Exceptions
Exception

Implements PHPExcel_Reader_IReader.

Definition at line 145 of file CSV.php.

References loadIntoExisting().

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

+ Here is the call graph for this function:

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

Loads PHPExcel from file into PHPExcel instance.

public

Parameters
string$pFilename
PHPExcel$objPHPExcel
Returns
PHPExcel
Exceptions
Exception

Definition at line 207 of file CSV.php.

References $_contiguousRow, $_sheetIndex, PHPExcel_Shared_String\ConvertEncoding(), PHPExcel\createSheet(), PHPExcel\getActiveSheet(), PHPExcel\getSheetCount(), and PHPExcel\setActiveSheetIndex().

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.");
}
// Skip BOM, if any
switch ($this->_inputEncoding) {
case 'UTF-8':
fgets($fileHandle, 4) == "\xEF\xBB\xBF" ?
fseek($fileHandle, 3) : fseek($fileHandle, 0);
break;
case 'UTF-16LE':
fgets($fileHandle, 3) == "\xFF\xFE" ?
fseek($fileHandle, 2) : fseek($fileHandle, 0);
break;
case 'UTF-16BE':
fgets($fileHandle, 3) == "\xFE\xFF" ?
fseek($fileHandle, 2) : fseek($fileHandle, 0);
break;
case 'UTF-32LE':
fgets($fileHandle, 5) == "\xFF\xFE\x00\x00" ?
fseek($fileHandle, 4) : fseek($fileHandle, 0);
break;
case 'UTF-32BE':
fgets($fileHandle, 5) == "\x00\x00\xFE\xFF" ?
fseek($fileHandle, 4) : fseek($fileHandle, 0);
break;
default:
break;
}
$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) ? $objPHPExcel->getActiveSheet()->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
$objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowDatum);
}
++$columnLetter;
}
++$currentRow;
}
// Close file
fclose($fileHandle);
if ($this->_contiguous) {
$this->_contiguousRow = $currentRow;
}
// Return
return $objPHPExcel;
} // function loadIntoExisting()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Reader_CSV::setContiguous (   $contiguous = false)

Set Contiguous.

public

Parameters
string$pValueInput encoding

Definition at line 391 of file CSV.php.

{
$this->_contiguous = (bool)$contiguous;
if (!$contiguous) {
$this->_contiguousRow = -1;
}
return $this;
} // function setInputEncoding()
PHPExcel_Reader_CSV::setDelimiter (   $pValue = ',')

Set delimiter.

public

Parameters
string$pValueDelimiter, defaults to ,
Returns
PHPExcel_Reader_CSV

Definition at line 311 of file CSV.php.

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

Set enclosure.

public

Parameters
string$pValueEnclosure, defaults to "
Returns
PHPExcel_Reader_CSV

Definition at line 333 of file CSV.php.

{
if ($pValue == '') {
$pValue = '"';
}
$this->_enclosure = $pValue;
return $this;
} // function setEnclosure()
PHPExcel_Reader_CSV::setInputEncoding (   $pValue = 'UTF-8')

Set input encoding.

public

Parameters
string$pValueInput encoding

Definition at line 181 of file CSV.php.

{
$this->_inputEncoding = $pValue;
return $this;
} // function setInputEncoding()
PHPExcel_Reader_CSV::setLineEnding (   $pValue = PHP_EOL)

Set line ending.

public

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

Definition at line 358 of file CSV.php.

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

Set read filter.

public

Parameters
PHPExcel_Reader_IReadFilter$pValue

Definition at line 170 of file CSV.php.

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

Set sheet index.

public

Parameters
int$pValueSheet index
Returns
PHPExcel_Reader_CSV

Definition at line 380 of file CSV.php.

{
$this->_sheetIndex = $pValue;
return $this;
} // function setSheetIndex()

Field Documentation

PHPExcel_Reader_CSV::$_contiguous = false
private

Definition at line 93 of file CSV.php.

Referenced by getContiguous().

PHPExcel_Reader_CSV::$_contiguousRow = -1
private

Definition at line 102 of file CSV.php.

Referenced by loadIntoExisting().

PHPExcel_Reader_CSV::$_delimiter = ','
private

Definition at line 61 of file CSV.php.

Referenced by getDelimiter().

PHPExcel_Reader_CSV::$_enclosure = '"'
private

Definition at line 69 of file CSV.php.

Referenced by getEnclosure().

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

Definition at line 53 of file CSV.php.

Referenced by getInputEncoding().

PHPExcel_Reader_CSV::$_lineEnding = PHP_EOL
private

Definition at line 77 of file CSV.php.

Referenced by getLineEnding().

PHPExcel_Reader_CSV::$_readFilter = null
private

Definition at line 110 of file CSV.php.

Referenced by getReadFilter().

PHPExcel_Reader_CSV::$_sheetIndex = 0
private

Definition at line 85 of file CSV.php.

Referenced by getSheetIndex(), and loadIntoExisting().


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