ILIAS  eassessment Revision 61809
 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 = PHP_EOL
 $_sheetIndex = 0
 $_preCalculateFormulas = true
 $_useBOM = false

Detailed Description

Definition at line 36 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 91 of file CSV.php.

{
$this->_phpExcel = $phpExcel;
}

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 246 of file CSV.php.

References $_delimiter, $_enclosure, and $_lineEnding.

Referenced by save().

{
if (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 141 of file CSV.php.

References $_delimiter.

{
}
PHPExcel_Writer_CSV::getEnclosure ( )

Get enclosure.

Returns
string

Definition at line 161 of file CSV.php.

References $_enclosure.

{
}
PHPExcel_Writer_CSV::getLineEnding ( )

Get line ending.

Returns
string

Definition at line 184 of file CSV.php.

References $_lineEnding.

{
}
PHPExcel_Writer_CSV::getPreCalculateFormulas ( )

Get Pre-Calculate Formulas.

Returns
boolean

Definition at line 284 of file CSV.php.

References $_preCalculateFormulas.

PHPExcel_Writer_CSV::getSheetIndex ( )

Get sheet index.

Returns
int

Definition at line 224 of file CSV.php.

References $_sheetIndex.

{
}
PHPExcel_Writer_CSV::getUseBOM ( )

Get whether BOM should be used.

Returns
boolean

Definition at line 204 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 101 of file CSV.php.

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

{
// Fetch sheet
$sheet = $this->_phpExcel->getSheet($this->_sheetIndex);
$saveDebugLog = PHPExcel_Calculation::getInstance()->writeDebugLog;
PHPExcel_Calculation::getInstance()->writeDebugLog = false;
$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
// Open file
$fileHandle = fopen($pFilename, 'wb+');
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);
PHPExcel_Calculation::getInstance()->writeDebugLog = $saveDebugLog;
}

+ 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 151 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 171 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 194 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 294 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 234 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 214 of file CSV.php.

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

Field Documentation

PHPExcel_Writer_CSV::$_delimiter = ','
private

Definition at line 49 of file CSV.php.

Referenced by _writeLine(), and getDelimiter().

PHPExcel_Writer_CSV::$_enclosure = '"'
private

Definition at line 56 of file CSV.php.

Referenced by _writeLine(), and getEnclosure().

PHPExcel_Writer_CSV::$_lineEnding = PHP_EOL
private

Definition at line 63 of file CSV.php.

Referenced by _writeLine(), and getLineEnding().

PHPExcel_Writer_CSV::$_phpExcel
private

Definition at line 42 of file CSV.php.

PHPExcel_Writer_CSV::$_preCalculateFormulas = true
private

Definition at line 77 of file CSV.php.

Referenced by getPreCalculateFormulas().

PHPExcel_Writer_CSV::$_sheetIndex = 0
private

Definition at line 70 of file CSV.php.

Referenced by getSheetIndex().

PHPExcel_Writer_CSV::$_useBOM = false
private

Definition at line 84 of file CSV.php.

Referenced by getUseBOM().


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