ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
PHPExcel_Writer_CSV Class Reference
+ Inheritance diagram for PHPExcel_Writer_CSV:
+ Collaboration diagram for PHPExcel_Writer_CSV:

Public Member Functions

 __construct (PHPExcel $phpExcel)
 Create a new PHPExcel_Writer_CSV.
 save ($pFilename=null)
 Save PHPExcel to file.
 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.
 getUseBOM ()
 Get whether BOM should be used.
 setUseBOM ($pValue=false)
 Set whether BOM should be used.
 getSheetIndex ()
 Get sheet index.
 setSheetIndex ($pValue=0)
 Set sheet index.
 getPreCalculateFormulas ()
 Get Pre-Calculate Formulas.
 setPreCalculateFormulas ($pValue=true)
 Set Pre-Calculate Formulas.

Private Member Functions

 _writeLine ($pFileHandle=null, $pValues=null)
 Write line to CSV file.

Private Attributes

 $_phpExcel
 $_delimiter
 $_enclosure
 $_lineEnding
 $_sheetIndex
 $_preCalculateFormulas = true
 $_useBOM = false

Detailed Description

Definition at line 57 of file CSV.php.

Constructor & Destructor Documentation

PHPExcel_Writer_CSV::__construct ( PHPExcel  $phpExcel)

Create a new PHPExcel_Writer_CSV.

Parameters
PHPExcel$phpExcelPHPExcel object

Definition at line 112 of file CSV.php.

{
$this->_phpExcel = $phpExcel;
$this->_delimiter = ',';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
}

Member Function Documentation

PHPExcel_Writer_CSV::_writeLine (   $pFileHandle = null,
  $pValues = null 
)
private

Write line to CSV file.

Parameters
mixed$pFileHandlePHP filehandle
array$pValuesArray containing values in a row
Exceptions
Exception

Definition at line 268 of file CSV.php.

References $_delimiter, $_enclosure, and $_lineEnding.

Referenced by save().

{
if (!is_null($pFileHandle) && is_array($pValues)) {
// No leading delimiter
$writeDelimiter = false;
// Build the line
$line = '';
foreach ($pValues as $element) {
// Escape enclosures
$element = str_replace($this->_enclosure, $this->_enclosure . $this->_enclosure, $element);
// Add delimiter
if ($writeDelimiter) {
} else {
$writeDelimiter = true;
}
// Add enclosed string
$line .= $this->_enclosure . $element . $this->_enclosure;
}
// Add line ending
// Write to file
fwrite($pFileHandle, $line);
} else {
throw new Exception("Invalid parameters passed.");
}
}

+ Here is the caller graph for this function:

PHPExcel_Writer_CSV::getDelimiter ( )

Get delimiter.

Returns
string

Definition at line 163 of file CSV.php.

References $_delimiter.

{
}
PHPExcel_Writer_CSV::getEnclosure ( )

Get enclosure.

Returns
string

Definition at line 183 of file CSV.php.

References $_enclosure.

{
}
PHPExcel_Writer_CSV::getLineEnding ( )

Get line ending.

Returns
string

Definition at line 206 of file CSV.php.

References $_lineEnding.

{
}
PHPExcel_Writer_CSV::getPreCalculateFormulas ( )

Get Pre-Calculate Formulas.

Returns
boolean

Definition at line 306 of file CSV.php.

References $_preCalculateFormulas.

PHPExcel_Writer_CSV::getSheetIndex ( )

Get sheet index.

Returns
int

Definition at line 246 of file CSV.php.

References $_sheetIndex.

{
}
PHPExcel_Writer_CSV::getUseBOM ( )

Get whether BOM should be used.

Returns
boolean

Definition at line 226 of file CSV.php.

References $_useBOM.

{
}
PHPExcel_Writer_CSV::save (   $pFilename = null)

Save PHPExcel to file.

Parameters
string$pFileName
Exceptions
Exception

Implements PHPExcel_Writer_IWriter.

Definition at line 126 of file CSV.php.

References $row, _writeLine(), PHPExcel_Calculation\getArrayReturnType(), PHPExcel_Calculation\RETURN_ARRAY_AS_VALUE, and PHPExcel_Calculation\setArrayReturnType().

{
// Fetch sheet
$sheet = $this->_phpExcel->getSheet($this->_sheetIndex);
$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
// Open file
$fileHandle = fopen($pFilename, 'w');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for writing.");
}
if ($this->_useBOM) {
// Write the UTF-8 BOM code
fwrite($fileHandle, "\xEF\xBB\xBF");
}
// Convert sheet to array
$cellsArray = $sheet->toArray('', $this->_preCalculateFormulas);
// Write rows to file
foreach ($cellsArray as $row) {
$this->_writeLine($fileHandle, $row);
}
// Close file
fclose($fileHandle);
}

+ Here is the call graph for this function:

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

Set delimiter.

Parameters
string$pValueDelimiter, defaults to ,
Returns
PHPExcel_Writer_CSV

Definition at line 173 of file CSV.php.

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

Set enclosure.

Parameters
string$pValueEnclosure, defaults to "
Returns
PHPExcel_Writer_CSV

Definition at line 193 of file CSV.php.

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

Set line ending.

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

Definition at line 216 of file CSV.php.

{
$this->_lineEnding = $pValue;
return $this;
}
PHPExcel_Writer_CSV::setPreCalculateFormulas (   $pValue = true)

Set Pre-Calculate Formulas.

Parameters
boolean$pValuePre-Calculate Formulas?
Returns
PHPExcel_Writer_CSV

Definition at line 316 of file CSV.php.

{
$this->_preCalculateFormulas = $pValue;
return $this;
}
PHPExcel_Writer_CSV::setSheetIndex (   $pValue = 0)

Set sheet index.

Parameters
int$pValueSheet index
Returns
PHPExcel_Writer_CSV

Definition at line 256 of file CSV.php.

{
$this->_sheetIndex = $pValue;
return $this;
}
PHPExcel_Writer_CSV::setUseBOM (   $pValue = false)

Set whether BOM should be used.

Parameters
boolean$pValueUse UTF-8 byte-order mark? Defaults to false
Returns
PHPExcel_Writer_CSV

Definition at line 236 of file CSV.php.

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

Field Documentation

PHPExcel_Writer_CSV::$_delimiter
private

Definition at line 70 of file CSV.php.

Referenced by _writeLine(), and getDelimiter().

PHPExcel_Writer_CSV::$_enclosure
private

Definition at line 77 of file CSV.php.

Referenced by _writeLine(), and getEnclosure().

PHPExcel_Writer_CSV::$_lineEnding
private

Definition at line 84 of file CSV.php.

Referenced by _writeLine(), and getLineEnding().

PHPExcel_Writer_CSV::$_phpExcel
private

Definition at line 63 of file CSV.php.

PHPExcel_Writer_CSV::$_preCalculateFormulas = true
private

Definition at line 98 of file CSV.php.

Referenced by getPreCalculateFormulas().

PHPExcel_Writer_CSV::$_sheetIndex
private

Definition at line 91 of file CSV.php.

Referenced by getSheetIndex().

PHPExcel_Writer_CSV::$_useBOM = false
private

Definition at line 105 of file CSV.php.

Referenced by getUseBOM().


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