Documentation

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.
$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?

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.
getSheetIndex()  : int
getUseBOM()  : bool
Get whether BOM should be used.
getUseDiskCaching()  : bool
Get use disk caching where possible?
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.
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?
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

$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 = ''

$sheetIndex

Sheet index to write.

private int $sheetIndex = 0

$useBOM

Whether to write a UTF8 BOM.

private bool $useBOM = false

$useDiskCaching

Use disk caching where possible?

private bool $useDiskCaching = false

Methods

getDelimiter()

public getDelimiter() : string
Return values
string

getDiskCachingDirectory()

Get disk caching directory.

public getDiskCachingDirectory() : string
Return values
string

getEnclosure()

public getEnclosure() : string
Return values
string

getEnclosureRequired()

public getEnclosureRequired() : bool
Return values
bool

getExcelCompatibility()

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

public getExcelCompatibility() : bool
Return values
bool

getIncludeCharts()

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
bool

getIncludeSeparatorLine()

Get whether a separator line should be included.

public getIncludeSeparatorLine() : bool
Return values
bool

getLineEnding()

public getLineEnding() : string
Return values
string

getOutputEncoding()

public getOutputEncoding() : string
Return values
string

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. 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
bool

getSheetIndex()

public getSheetIndex() : int
Return values
int

getUseBOM()

Get whether BOM should be used.

public getUseBOM() : bool
Return values
bool

getUseDiskCaching()

Get use disk caching where possible?

public getUseDiskCaching() : bool
Return values
bool

openFileHandle()

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

setDelimiter()

public setDelimiter(string $delimiter) : self
Parameters
$delimiter : string
Return values
self

setEnclosure()

public setEnclosure([string $enclosure = '"' ]) : self
Parameters
$enclosure : string = '"'
Return values
self

setEnclosureRequired()

public setEnclosureRequired(bool $value) : self
Parameters
$value : bool
Return values
self

setExcelCompatibility()

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
self

setIncludeCharts()

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
$this

setIncludeSeparatorLine()

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
self

setLineEnding()

public setLineEnding(string $lineEnding) : self
Parameters
$lineEnding : string
Return values
self

setOutputEncoding()

public setOutputEncoding(string $outputEnconding) : self
Parameters
$outputEnconding : string
Return values
self

setPreCalculateFormulas()

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
$this

setSheetIndex()

public setSheetIndex(int $sheetIndex) : self
Parameters
$sheetIndex : int
Return values
self

setUseBOM()

Set whether BOM should be used, typically when non-ASCII characters are used.

public setUseBOM(bool $useBOM) : self
Parameters
$useBOM : bool
Return values
self

setUseDiskCaching()

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
$this

maybeCloseFileHandle()

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(mixed $element) : string
Parameters
$element : mixed
Return values
string

writeLine()

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


        
On this page

Search results