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);
setOutputEncoding($pValue)
Set output encoding.
setIncludeSeparatorLine($pValue)
Set whether a separator line should be included as the first line of the file.
getLineEnding()
Get line ending.
static getArrayReturnType()
Return the Array Return Type (Array or Value of first element in the array).
setExcelCompatibility($pValue)
Set whether the file should be saved with full Excel Compatibility.
setSheetIndex($pValue)
Set sheet index.
getSheetIndex()
Get sheet index.
getExcelCompatibility()
Get whether the file should be saved with full Excel Compatibility.
setDelimiter($pValue)
Set delimiter.
writeLine($pFileHandle, array $pValues)
Write line to CSV file.
getEnclosure()
Get enclosure.
setEnclosure($pValue='"')
Set enclosure.
setUseBOM($pValue)
Set whether BOM should be used.
const RETURN_ARRAY_AS_VALUE
getOutputEncoding()
Get output encoding.
getIncludeSeparatorLine()
Get whether a separator line should be included.
static setArrayReturnType($returnType)
Set the Array Return Type (Array or Value of first element in the array).
setEnclosureRequired(bool $value)
__construct(Spreadsheet $spreadsheet)
Create a new CSV.
static getInstance(?Spreadsheet $spreadsheet=null)
Get an instance of this class.
setLineEnding($pValue)
Set line ending.
getUseBOM()
Get whether BOM should be used.
getDelimiter()
Get delimiter.
openFileHandle($filename)
Open file handle.
save($pFilename)
Save PhpSpreadsheet to file.
maybeCloseFileHandle()
Close file handle only if we opened it ourselves.