89 public function save($pFilename): void
92 $sheet = $this->spreadsheet->getSheet($this->sheetIndex);
102 if ($this->excelCompatibility) {
112 fwrite($this->fileHandle,
"\xEF\xBB\xBF");
115 if ($this->includeSeparatorLine) {
117 fwrite($this->fileHandle,
'sep=' . $this->
getDelimiter() . $this->lineEnding);
121 $maxCol = $sheet->getHighestDataColumn();
122 $maxRow = $sheet->getHighestDataRow();
127 $cellsArray = $sheet->rangeToArray(
'A' .
$row .
':' . $maxCol .
$row,
'', $this->preCalculateFormulas);
129 $this->
writeLine($this->fileHandle, $cellsArray[0]);
156 $this->delimiter = $pValue;
180 $this->enclosure = $pValue;
204 $this->lineEnding = $pValue;
228 $this->useBOM = $pValue;
252 $this->includeSeparatorLine = $pValue;
277 $this->excelCompatibility = $pValue;
301 $this->sheetIndex = $pValue;
325 $this->outputEncoding = $pValue;
334 $this->enclosureRequired = $value;
350 private function writeLine($pFileHandle, array $pValues): void
358 foreach ($pValues as $element) {
367 if (!$this->enclosureRequired && strpbrk($element,
"$delimiter$enclosure\n") ===
false) {
381 if ($this->outputEncoding !=
'') {
382 $line = mb_convert_encoding($line, $this->outputEncoding);
384 fwrite($pFileHandle, $line);
An exception for terminatinating execution or to throw for unit testing.
const RETURN_ARRAY_AS_VALUE
static setArrayReturnType($returnType)
Set the Array Return Type (Array or Value of first element in the array).
static getArrayReturnType()
Return the Array Return Type (Array or Value of first element in the array).
static getInstance(?Spreadsheet $spreadsheet=null)
Get an instance of this class.
openFileHandle($filename)
Open file handle.
maybeCloseFileHandle()
Close file handle only if we opened it ourselves.
getDelimiter()
Get delimiter.
setExcelCompatibility($pValue)
Set whether the file should be saved with full Excel Compatibility.
writeLine($pFileHandle, array $pValues)
Write line to CSV file.
setOutputEncoding($pValue)
Set output encoding.
__construct(Spreadsheet $spreadsheet)
Create a new CSV.
setSheetIndex($pValue)
Set sheet index.
getOutputEncoding()
Get output encoding.
save($pFilename)
Save PhpSpreadsheet to file.
getEnclosure()
Get enclosure.
setUseBOM($pValue)
Set whether BOM should be used.
setIncludeSeparatorLine($pValue)
Set whether a separator line should be included as the first line of the file.
setEnclosureRequired(bool $value)
getIncludeSeparatorLine()
Get whether a separator line should be included.
setLineEnding($pValue)
Set line ending.
getLineEnding()
Get line ending.
getExcelCompatibility()
Get whether the file should be saved with full Excel Compatibility.
setDelimiter($pValue)
Set delimiter.
getUseBOM()
Get whether BOM should be used.
setEnclosure($pValue='"')
Set enclosure.
getSheetIndex()
Get sheet index.