ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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. More...
 
 save ($pFilename=null)
 Save PHPExcel to file. More...
 
 getDelimiter ()
 Get delimiter. More...
 
 setDelimiter ($pValue=',')
 Set delimiter. More...
 
 getEnclosure ()
 Get enclosure. More...
 
 setEnclosure ($pValue='"')
 Set enclosure. More...
 
 getLineEnding ()
 Get line ending. More...
 
 setLineEnding ($pValue=PHP_EOL)
 Set line ending. More...
 
 getUseBOM ()
 Get whether BOM should be used. More...
 
 setUseBOM ($pValue=false)
 Set whether BOM should be used. More...
 
 getExcelCompatibility ()
 Get whether the file should be saved with full Excel Compatibility. More...
 
 setExcelCompatibility ($pValue=false)
 Set whether the file should be saved with full Excel Compatibility. More...
 
 getSheetIndex ()
 Get sheet index. More...
 
 setSheetIndex ($pValue=0)
 Set sheet index. More...
 
- Public Member Functions inherited from PHPExcel_Writer_Abstract
 getIncludeCharts ()
 Write charts in workbook? If this is true, then the Writer will write definitions for any charts that exist in the PHPExcel object. More...
 
 setIncludeCharts ($pValue=FALSE)
 Set write charts in workbook Set to true, to advise the Writer to include any charts that exist in the PHPExcel object. More...
 
 getPreCalculateFormulas ()
 Get Pre-Calculate Formulas flag If this is true (the default), then the writer will recalculate all formulae in a workbook when saving, so that the pre-calculated values are immediately available to MS Excel or other office spreadsheet viewer when opening the file If false, then formulae are not calculated on save. More...
 
 setPreCalculateFormulas ($pValue=TRUE)
 Set Pre-Calculate Formulas Set to true (the default) to advise the Writer to calculate all formulae on save Set to false to prevent precalculation of formulae on save. More...
 
 getUseDiskCaching ()
 Get use disk caching where possible? More...
 
 setUseDiskCaching ($pValue=FALSE, $pDirectory=NULL)
 Set use disk caching where possible? More...
 
 getDiskCachingDirectory ()
 Get disk caching directory. More...
 
 save ($pFilename=NULL)
 Save PHPExcel to file. More...
 

Private Member Functions

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

Private Attributes

 $_phpExcel
 
 $_delimiter = ','
 
 $_enclosure = '"'
 
 $_lineEnding = PHP_EOL
 
 $_sheetIndex = 0
 
 $_useBOM = false
 
 $_excelCompatibility = false
 

Additional Inherited Members

- Protected Attributes inherited from PHPExcel_Writer_Abstract
 $_includeCharts = FALSE
 
 $_preCalculateFormulas = TRUE
 
 $_useDiskCaching = FALSE
 
 $_diskCachingDirectory = './'
 

Detailed Description

Definition at line 36 of file CSV.php.

Constructor & Destructor Documentation

◆ __construct()

PHPExcel_Writer_CSV::__construct ( PHPExcel  $phpExcel)

Create a new PHPExcel_Writer_CSV.

Parameters
PHPExcel$phpExcelPHPExcel object

Definition at line 91 of file CSV.php.

91 {
92 $this->_phpExcel = $phpExcel;
93 }

Member Function Documentation

◆ _writeLine()

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
PHPExcel_Writer_Exception

Definition at line 277 of file CSV.php.

277 {
278 if (is_array($pValues)) {
279 // No leading delimiter
280 $writeDelimiter = false;
281
282 // Build the line
283 $line = '';
284
285 foreach ($pValues as $element) {
286 // Escape enclosures
287 $element = str_replace($this->_enclosure, $this->_enclosure . $this->_enclosure, $element);
288
289 // Add delimiter
290 if ($writeDelimiter) {
291 $line .= $this->_delimiter;
292 } else {
293 $writeDelimiter = true;
294 }
295
296 // Add enclosed string
297 $line .= $this->_enclosure . $element . $this->_enclosure;
298 }
299
300 // Add line ending
301 $line .= $this->_lineEnding;
302
303 // Write to file
304 fwrite($pFileHandle, $line);
305 } else {
306 throw new PHPExcel_Writer_Exception("Invalid data row passed to CSV writer.");
307 }
308 }

References $_delimiter, $_enclosure, and $_lineEnding.

Referenced by save().

+ Here is the caller graph for this function:

◆ getDelimiter()

PHPExcel_Writer_CSV::getDelimiter ( )

Get delimiter.

Returns
string

Definition at line 151 of file CSV.php.

151 {
152 return $this->_delimiter;
153 }

References $_delimiter.

Referenced by save().

+ Here is the caller graph for this function:

◆ getEnclosure()

PHPExcel_Writer_CSV::getEnclosure ( )

Get enclosure.

Returns
string

Definition at line 171 of file CSV.php.

171 {
172 return $this->_enclosure;
173 }

References $_enclosure.

◆ getExcelCompatibility()

PHPExcel_Writer_CSV::getExcelCompatibility ( )

Get whether the file should be saved with full Excel Compatibility.

Returns
boolean

Definition at line 234 of file CSV.php.

234 {
236 }

References $_excelCompatibility.

◆ getLineEnding()

PHPExcel_Writer_CSV::getLineEnding ( )

Get line ending.

Returns
string

Definition at line 194 of file CSV.php.

194 {
195 return $this->_lineEnding;
196 }

References $_lineEnding.

◆ getSheetIndex()

PHPExcel_Writer_CSV::getSheetIndex ( )

Get sheet index.

Returns
int

Definition at line 255 of file CSV.php.

255 {
256 return $this->_sheetIndex;
257 }

References $_sheetIndex.

◆ getUseBOM()

PHPExcel_Writer_CSV::getUseBOM ( )

Get whether BOM should be used.

Returns
boolean

Definition at line 214 of file CSV.php.

214 {
215 return $this->_useBOM;
216 }

References $_useBOM.

◆ save()

PHPExcel_Writer_CSV::save (   $pFilename = null)

Save PHPExcel to file.

Parameters
string$pFilename
Exceptions
PHPExcel_Writer_Exception

Implements PHPExcel_Writer_IWriter.

Definition at line 101 of file CSV.php.

101 {
102 // Fetch sheet
103 $sheet = $this->_phpExcel->getSheet($this->_sheetIndex);
104
105 $saveDebugLog = PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->getWriteDebugLog();
106 PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->setWriteDebugLog(FALSE);
107 $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
109
110 // Open file
111 $fileHandle = fopen($pFilename, 'wb+');
112 if ($fileHandle === false) {
113 throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing.");
114 }
115
116 if ($this->_excelCompatibility) {
117 fwrite($fileHandle, "\xEF\xBB\xBF"); // Enforce UTF-8 BOM Header
118 $this->setEnclosure('"'); // Set enclosure to "
119 $this->setDelimiter(";"); // Set delimiter to a semi-colon
120 $this->setLineEnding("\r\n");
121 fwrite($fileHandle, 'sep=' . $this->getDelimiter() . $this->_lineEnding);
122 } elseif ($this->_useBOM) {
123 // Write the UTF-8 BOM code if required
124 fwrite($fileHandle, "\xEF\xBB\xBF");
125 }
126
127 // Identify the range that we need to extract from the worksheet
128 $maxCol = $sheet->getHighestDataColumn();
129 $maxRow = $sheet->getHighestDataRow();
130
131 // Write rows to file
132 for($row = 1; $row <= $maxRow; ++$row) {
133 // Convert the row to an array...
134 $cellsArray = $sheet->rangeToArray('A'.$row.':'.$maxCol.$row,'', $this->_preCalculateFormulas);
135 // ... and write to the file
136 $this->_writeLine($fileHandle, $cellsArray[0]);
137 }
138
139 // Close file
140 fclose($fileHandle);
141
142 PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
143 PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog);
144 }
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static getArrayReturnType()
Return the Array Return Type (Array or Value of first element in the array)
static setArrayReturnType($returnType)
Set the Array Return Type (Array or Value of first element in the array)
_writeLine($pFileHandle=null, $pValues=null)
Write line to CSV file.
Definition: CSV.php:277
setDelimiter($pValue=',')
Set delimiter.
Definition: CSV.php:161
setLineEnding($pValue=PHP_EOL)
Set line ending.
Definition: CSV.php:204
setEnclosure($pValue='"')
Set enclosure.
Definition: CSV.php:181
getDelimiter()
Get delimiter.
Definition: CSV.php:151

References $row, _writeLine(), PHPExcel_Calculation\getArrayReturnType(), getDelimiter(), PHPExcel_Calculation\getInstance(), PHPExcel_Calculation\RETURN_ARRAY_AS_VALUE, PHPExcel_Calculation\setArrayReturnType(), setDelimiter(), setEnclosure(), and setLineEnding().

+ Here is the call graph for this function:

◆ setDelimiter()

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

Set delimiter.

Parameters
string$pValueDelimiter, defaults to ,
Returns
PHPExcel_Writer_CSV

Definition at line 161 of file CSV.php.

161 {
162 $this->_delimiter = $pValue;
163 return $this;
164 }

Referenced by save().

+ Here is the caller graph for this function:

◆ setEnclosure()

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

Set enclosure.

Parameters
string$pValueEnclosure, defaults to "
Returns
PHPExcel_Writer_CSV

Definition at line 181 of file CSV.php.

181 {
182 if ($pValue == '') {
183 $pValue = null;
184 }
185 $this->_enclosure = $pValue;
186 return $this;
187 }

Referenced by save().

+ Here is the caller graph for this function:

◆ setExcelCompatibility()

PHPExcel_Writer_CSV::setExcelCompatibility (   $pValue = false)

Set whether the file should be saved with full Excel Compatibility.

Parameters
boolean$pValueSet the file to be written as a fully Excel compatible csv file Note that this overrides other settings such as useBOM, enclosure and delimiter
Returns
PHPExcel_Writer_CSV

Definition at line 245 of file CSV.php.

245 {
246 $this->_excelCompatibility = $pValue;
247 return $this;
248 }

◆ setLineEnding()

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

204 {
205 $this->_lineEnding = $pValue;
206 return $this;
207 }

Referenced by save().

+ Here is the caller graph for this function:

◆ setSheetIndex()

PHPExcel_Writer_CSV::setSheetIndex (   $pValue = 0)

Set sheet index.

Parameters
int$pValueSheet index
Returns
PHPExcel_Writer_CSV

Definition at line 265 of file CSV.php.

265 {
266 $this->_sheetIndex = $pValue;
267 return $this;
268 }

◆ setUseBOM()

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

224 {
225 $this->_useBOM = $pValue;
226 return $this;
227 }

Field Documentation

◆ $_delimiter

PHPExcel_Writer_CSV::$_delimiter = ','
private

Definition at line 49 of file CSV.php.

Referenced by _writeLine(), and getDelimiter().

◆ $_enclosure

PHPExcel_Writer_CSV::$_enclosure = '"'
private

Definition at line 56 of file CSV.php.

Referenced by _writeLine(), and getEnclosure().

◆ $_excelCompatibility

PHPExcel_Writer_CSV::$_excelCompatibility = false
private

Definition at line 84 of file CSV.php.

Referenced by getExcelCompatibility().

◆ $_lineEnding

PHPExcel_Writer_CSV::$_lineEnding = PHP_EOL
private

Definition at line 63 of file CSV.php.

Referenced by _writeLine(), and getLineEnding().

◆ $_phpExcel

PHPExcel_Writer_CSV::$_phpExcel
private

Definition at line 42 of file CSV.php.

◆ $_sheetIndex

PHPExcel_Writer_CSV::$_sheetIndex = 0
private

Definition at line 70 of file CSV.php.

Referenced by getSheetIndex().

◆ $_useBOM

PHPExcel_Writer_CSV::$_useBOM = false
private

Definition at line 77 of file CSV.php.

Referenced by getUseBOM().


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