Csv
extends BaseWriter
in package
Table of Contents
Properties
- $fileHandle : resource
- $includeCharts : bool
- Write charts that are defined in the workbook? Identifies whether the Writer should write definitions for any charts that exist in the PhpSpreadsheet object.
- $preCalculateFormulas : bool
- Pre-calculate formulas Forces PhpSpreadsheet to 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.
- $delimiter : string
- Delimiter.
- $diskCachingDirectory : string
- Disk caching directory.
- $enclosure : string
- Enclosure.
- $enclosureRequired : bool
- $excelCompatibility : bool
- Whether to write a fully Excel compatible CSV file.
- $includeSeparatorLine : bool
- Whether to write a Separator line as the first line of the file sep=x.
- $lineEnding : string
- Line ending.
- $outputEncoding : string
- Output encoding.
- $preferHyperlinkToLabel : bool
- $sheetIndex : int
- Sheet index to write.
- $shouldCloseFile : bool
- $spreadsheet : Spreadsheet
- PhpSpreadsheet object.
- $useBOM : bool
- Whether to write a UTF8 BOM.
- $useDiskCaching : bool
- Use disk caching where possible?
- $variableColumns : bool
- Whether number of columns should be allowed to vary between rows, or use a fixed range based on the max column overall.
Methods
- __construct() : mixed
- Create a new CSV.
- getDelimiter() : string
- getDiskCachingDirectory() : string
- Get disk caching directory.
- getEnclosure() : string
- getEnclosureRequired() : bool
- getExcelCompatibility() : bool
- Get whether the file should be saved with full Excel Compatibility.
- getIncludeCharts() : bool
- Write charts in workbook? If this is true, then the Writer will write definitions for any charts that exist in the PhpSpreadsheet object.
- getIncludeSeparatorLine() : bool
- Get whether a separator line should be included.
- getLineEnding() : string
- getOutputEncoding() : string
- getPreCalculateFormulas() : bool
- 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. This is faster for saving in PhpSpreadsheet, but slower when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself.
- getPreferHyperlinkToLabel() : bool
- Get whether hyperlink or label should be output.
- getSheetIndex() : int
- getUseBOM() : bool
- Get whether BOM should be used.
- getUseDiskCaching() : bool
- Get use disk caching where possible?
- getVariableColumns() : bool
- Get whether number of columns should be allowed to vary between rows, or use a fixed range based on the max column overall.
- openFileHandle() : void
- Open file handle.
- save() : void
- Save PhpSpreadsheet to file.
- setDelimiter() : self
- setEnclosure() : self
- setEnclosureRequired() : self
- setExcelCompatibility() : self
- Set whether the file should be saved with full Excel Compatibility.
- setIncludeCharts() : $this
- Set write charts in workbook Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
- setIncludeSeparatorLine() : self
- Set whether a separator line should be included as the first line of the file.
- setLineEnding() : self
- setOutputEncoding() : self
- setPreCalculateFormulas() : $this
- 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.
- setPreferHyperlinkToLabel() : self
- Set whether hyperlink or label should be output.
- setSheetIndex() : self
- setUseBOM() : self
- Set whether BOM should be used, typically when non-ASCII characters are used.
- setUseDiskCaching() : $this
- Set use disk caching where possible?
- setVariableColumns() : self
- Set whether number of columns should be allowed to vary between rows, or use a fixed range based on the max column overall.
- maybeCloseFileHandle() : void
- Close file handle only if we opened it ourselves.
- processFlags() : void
- elementToString() : string
- Convert boolean to TRUE/FALSE; otherwise return element cast to string.
- writeLine() : void
- Write line to CSV file.
Properties
$fileHandle
protected
resource
$fileHandle
$includeCharts
Write charts that are defined in the workbook? Identifies whether the Writer should write definitions for any charts that exist in the PhpSpreadsheet object.
protected
bool
$includeCharts
= false
$preCalculateFormulas
Pre-calculate formulas Forces PhpSpreadsheet to 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.
protected
bool
$preCalculateFormulas
= true
$delimiter
Delimiter.
private
string
$delimiter
= ','
$diskCachingDirectory
Disk caching directory.
private
string
$diskCachingDirectory
= './'
$enclosure
Enclosure.
private
string
$enclosure
= '"'
$enclosureRequired
private
bool
$enclosureRequired
= true
$excelCompatibility
Whether to write a fully Excel compatible CSV file.
private
bool
$excelCompatibility
= false
$includeSeparatorLine
Whether to write a Separator line as the first line of the file sep=x.
private
bool
$includeSeparatorLine
= false
$lineEnding
Line ending.
private
string
$lineEnding
= PHP_EOL
$outputEncoding
Output encoding.
private
string
$outputEncoding
= ''
$preferHyperlinkToLabel
private
bool
$preferHyperlinkToLabel
= false
$sheetIndex
Sheet index to write.
private
int
$sheetIndex
= 0
$shouldCloseFile
private
bool
$shouldCloseFile
$spreadsheet
PhpSpreadsheet object.
private
Spreadsheet
$spreadsheet
$useBOM
Whether to write a UTF8 BOM.
private
bool
$useBOM
= false
$useDiskCaching
Use disk caching where possible?
private
bool
$useDiskCaching
= false
$variableColumns
Whether number of columns should be allowed to vary between rows, or use a fixed range based on the max column overall.
private
bool
$variableColumns
= false
Methods
__construct()
Create a new CSV.
public
__construct(Spreadsheet $spreadsheet) : mixed
Parameters
- $spreadsheet : Spreadsheet
-
The spreadsheet that we want to save using this Writer
getDelimiter()
public
getDelimiter() : string
Return values
stringgetDiskCachingDirectory()
Get disk caching directory.
public
getDiskCachingDirectory() : string
Return values
stringgetEnclosure()
public
getEnclosure() : string
Return values
stringgetEnclosureRequired()
public
getEnclosureRequired() : bool
Return values
boolgetExcelCompatibility()
Get whether the file should be saved with full Excel Compatibility.
public
getExcelCompatibility() : bool
Return values
boolgetIncludeCharts()
Write charts in workbook? If this is true, then the Writer will write definitions for any charts that exist in the PhpSpreadsheet object.
public
getIncludeCharts() : bool
If false (the default) it will ignore any charts defined in the PhpSpreadsheet object.
Return values
boolgetIncludeSeparatorLine()
Get whether a separator line should be included.
public
getIncludeSeparatorLine() : bool
Return values
boolgetLineEnding()
public
getLineEnding() : string
Return values
stringgetOutputEncoding()
public
getOutputEncoding() : string
Return values
stringgetPreCalculateFormulas()
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. This is faster for saving in PhpSpreadsheet, but slower when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself.
public
getPreCalculateFormulas() : bool
Return values
boolgetPreferHyperlinkToLabel()
Get whether hyperlink or label should be output.
public
getPreferHyperlinkToLabel() : bool
Return values
boolgetSheetIndex()
public
getSheetIndex() : int
Return values
intgetUseBOM()
Get whether BOM should be used.
public
getUseBOM() : bool
Return values
boolgetUseDiskCaching()
Get use disk caching where possible?
public
getUseDiskCaching() : bool
Return values
boolgetVariableColumns()
Get whether number of columns should be allowed to vary between rows, or use a fixed range based on the max column overall.
public
getVariableColumns() : bool
Return values
boolopenFileHandle()
Open file handle.
public
openFileHandle(resource|string $filename) : void
Parameters
- $filename : resource|string
save()
Save PhpSpreadsheet to file.
public
save(resource|string $filename[, int $flags = 0 ]) : void
Parameters
- $filename : resource|string
- $flags : int = 0
-
Flags that can change the behaviour of the Writer: self::SAVE_WITH_CHARTS Save any charts that are defined (if the Writer supports Charts) self::DISABLE_PRECALCULATE_FORMULAE Don't Precalculate formulae before saving the file
setDelimiter()
public
setDelimiter(string $delimiter) : self
Parameters
- $delimiter : string
Return values
selfsetEnclosure()
public
setEnclosure([string $enclosure = '"' ]) : self
Parameters
- $enclosure : string = '"'
Return values
selfsetEnclosureRequired()
public
setEnclosureRequired(bool $value) : self
Parameters
- $value : bool
Return values
selfsetExcelCompatibility()
Set whether the file should be saved with full Excel Compatibility.
public
setExcelCompatibility(bool $excelCompatibility) : self
Parameters
- $excelCompatibility : bool
-
Set the file to be written as a fully Excel compatible csv file Note that this overrides other settings such as useBOM, enclosure and delimiter
Return values
selfsetIncludeCharts()
Set write charts in workbook Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
public
setIncludeCharts(bool $includeCharts) : $this
Set to false (the default) to ignore charts.
Parameters
- $includeCharts : bool
Return values
$thissetIncludeSeparatorLine()
Set whether a separator line should be included as the first line of the file.
public
setIncludeSeparatorLine(bool $includeSeparatorLine) : self
Parameters
- $includeSeparatorLine : bool
Return values
selfsetLineEnding()
public
setLineEnding(string $lineEnding) : self
Parameters
- $lineEnding : string
Return values
selfsetOutputEncoding()
public
setOutputEncoding(string $outputEnconding) : self
Parameters
- $outputEnconding : string
Return values
selfsetPreCalculateFormulas()
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.
public
setPreCalculateFormulas(bool $precalculateFormulas) : $this
Parameters
- $precalculateFormulas : bool
-
Pre-Calculate Formulas?
Return values
$thissetPreferHyperlinkToLabel()
Set whether hyperlink or label should be output.
public
setPreferHyperlinkToLabel(bool $preferHyperlinkToLabel) : self
Parameters
- $preferHyperlinkToLabel : bool
Return values
selfsetSheetIndex()
public
setSheetIndex(int $sheetIndex) : self
Parameters
- $sheetIndex : int
Return values
selfsetUseBOM()
Set whether BOM should be used, typically when non-ASCII characters are used.
public
setUseBOM(bool $useBOM) : self
Parameters
- $useBOM : bool
Return values
selfsetUseDiskCaching()
Set use disk caching where possible?
public
setUseDiskCaching(bool $useDiskCache[, string|null $cacheDirectory = null ]) : $this
Parameters
- $useDiskCache : bool
- $cacheDirectory : string|null = null
-
Disk caching directory
Return values
$thissetVariableColumns()
Set whether number of columns should be allowed to vary between rows, or use a fixed range based on the max column overall.
public
setVariableColumns(bool $pValue) : self
Parameters
- $pValue : bool
Return values
selfmaybeCloseFileHandle()
Close file handle only if we opened it ourselves.
protected
maybeCloseFileHandle() : void
processFlags()
protected
processFlags(int $flags) : void
Parameters
- $flags : int
elementToString()
Convert boolean to TRUE/FALSE; otherwise return element cast to string.
private
static elementToString(null|bool|float|int|string|Stringable $element) : string
Parameters
- $element : null|bool|float|int|string|Stringable
-
element to be converted
Return values
stringwriteLine()
Write line to CSV file.
private
writeLine(resource $fileHandle, array<string|int, mixed> $values) : void
Parameters
- $fileHandle : resource
-
PHP filehandle
- $values : array<string|int, mixed>
-
Array containing values in a row