Html
extends BaseWriter
in package
Table of Contents
Constants
- BODY_LINE = ' <body>' . PHP_EOL
- BORDER_ARR = [\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE => self::BORDER_NONE, \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT => '1px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT => '1px dotted', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED => '1px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED => '1px dotted', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE => '3px double', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR => '1px solid', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM => '2px solid', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT => '2px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT => '2px dotted', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT => '2px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK => '3px solid']
- BORDER_NONE = 'none'
- COMMENT_HTML_TAGS_PLAINTEXT = true
- Migration aid to tell if html tags will be treated as plaintext in comments.
Properties
- $conditionalFormatting : bool
- Conditional Formatting Enables conditional formatting in writer, disabled here, must be enabled in writer via a setter.
- $embedImages : bool
- embed images, or link to images.
- $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.
- $isPdf : bool
- Is the current writer creating PDF?
- $ltrSheets : bool
- $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.
- $rtlSheets : bool
- $spreadsheet : Spreadsheet
- Spreadsheet object.
- $tableFormats : bool
- Table formats Enables table formats in writer, disabled here, must be enabled in writer via a setter.
Methods
- __construct() : mixed
- Create a new HTML.
- buildCSS() : array<string|int, array<string|int, string>>
- Build CSS styles.
- formatColor() : string
- Add color to formatted string as inline style.
- formatColorStatic() : string
- Add color to formatted string as inline style.
- generateHtmlAll() : string
- Save Spreadsheet as html to variable.
- generateHTMLFooter() : string
- Generate HTML footer.
- generateHTMLHeader() : string
- Generate HTML header.
- generateNavigation() : string
- Generate sheet tabs.
- generateSheetData() : string
- Generate sheet data.
- generateStyles() : string
- Generate CSS styles.
- getBetterBoolean() : bool
- getConditionalFormatting() : bool
- getDiskCachingDirectory() : string
- Get disk caching directory.
- getEmbedImages() : bool
- Get embed images.
- getGenerateSheetNavigationBlock() : bool
- Get sheet index.
- getImagesRoot() : string
- Get images root.
- 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.
- getOrientation() : string|null
- 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|null
- Get sheet index.
- getTableFormats() : bool
- getUseDiskCaching() : bool
- Get use disk caching where possible?
- getUseInlineCss() : bool
- Get use inline CSS?
- openFileHandle() : void
- Open file handle.
- save() : void
- Save Spreadsheet to file.
- setBetterBoolean() : self
- setConditionalFormatting() : self
- setEditHtmlCallback() : void
- Set a callback to edit the entire HTML.
- setEmbedImages() : $this
- Set embed images.
- setGenerateSheetNavigationBlock() : $this
- Set sheet index.
- setImagesRoot() : $this
- Set images root.
- setIncludeCharts() : $this
- Set write charts in workbook Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
- 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() : $this
- Set sheet index.
- setTableFormats() : self
- setUseDiskCaching() : $this
- Set use disk caching where possible?
- setUseInlineCss() : $this
- Set use inline CSS?
- winFileToUrl() : string
- Convert Windows file name to file protocol URL.
- writeAllSheets() : $this
- Write all sheets (resets sheetIndex to NULL).
- checkRtlAndLtr() : void
- maybeCloseFileHandle() : void
- Close file handle only if we opened it ourselves.
- processFlags() : void
Constants
BODY_LINE
public
mixed
BODY_LINE
= ' <body>' . PHP_EOL
BORDER_ARR
public
mixed
BORDER_ARR
= [\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE => self::BORDER_NONE, \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT => '1px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT => '1px dotted', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED => '1px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED => '1px dotted', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE => '3px double', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR => '1px solid', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM => '2px solid', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT => '2px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT => '2px dotted', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT => '2px dashed', \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK => '3px solid']
BORDER_NONE
public
mixed
BORDER_NONE
= 'none'
COMMENT_HTML_TAGS_PLAINTEXT
Migration aid to tell if html tags will be treated as plaintext in comments.
public
mixed
COMMENT_HTML_TAGS_PLAINTEXT
= true
if ( defined( \PhpOffice\PhpSpreadsheet\Writer\Html::class . '::COMMENT_HTML_TAGS_PLAINTEXT' ) ) { new logic with styling in TextRun elements } else { old logic with styling via Html tags }.
Properties
$conditionalFormatting
Conditional Formatting Enables conditional formatting in writer, disabled here, must be enabled in writer via a setter.
protected
bool
$conditionalFormatting
= false
$embedImages
embed images, or link to images.
protected
bool
$embedImages
= false
$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
$isPdf
Is the current writer creating PDF?
protected
bool
$isPdf
= false
$ltrSheets
protected
bool
$ltrSheets
= 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
$rtlSheets
protected
bool
$rtlSheets
= false
$spreadsheet
Spreadsheet object.
protected
Spreadsheet
$spreadsheet
$tableFormats
Table formats Enables table formats in writer, disabled here, must be enabled in writer via a setter.
protected
bool
$tableFormats
= false
Methods
__construct()
Create a new HTML.
public
__construct(Spreadsheet $spreadsheet) : mixed
Parameters
- $spreadsheet : Spreadsheet
-
The spreadsheet that we want to save using this Writer
buildCSS()
Build CSS styles.
public
buildCSS([bool $generateSurroundingHTML = true ]) : array<string|int, array<string|int, string>>
Parameters
- $generateSurroundingHTML : bool = true
-
Generate surrounding HTML style? (html { })
Return values
array<string|int, array<string|int, string>>formatColor()
Add color to formatted string as inline style.
public
formatColor(string $value, string $format) : string
Parameters
- $value : string
-
Plain formatted value without color
- $format : string
-
Format code
Return values
stringformatColorStatic()
Add color to formatted string as inline style.
public
static formatColorStatic(string $value, string $format) : string
Parameters
- $value : string
-
Plain formatted value without color
- $format : string
-
Format code
Return values
stringgenerateHtmlAll()
Save Spreadsheet as html to variable.
public
generateHtmlAll() : string
Return values
stringgenerateHTMLFooter()
Generate HTML footer.
public
generateHTMLFooter() : string
Return values
stringgenerateHTMLHeader()
Generate HTML header.
public
generateHTMLHeader([bool $includeStyles = false ]) : string
Parameters
- $includeStyles : bool = false
-
Include styles?
Return values
stringgenerateNavigation()
Generate sheet tabs.
public
generateNavigation() : string
Return values
stringgenerateSheetData()
Generate sheet data.
public
generateSheetData() : string
Return values
stringgenerateStyles()
Generate CSS styles.
public
generateStyles([bool $generateSurroundingHTML = true ]) : string
Parameters
- $generateSurroundingHTML : bool = true
-
Generate surrounding HTML tags? (<style> and </style>)
Return values
stringgetBetterBoolean()
public
getBetterBoolean() : bool
Return values
boolgetConditionalFormatting()
public
getConditionalFormatting() : bool
Return values
boolgetDiskCachingDirectory()
Get disk caching directory.
public
getDiskCachingDirectory() : string
Return values
stringgetEmbedImages()
Get embed images.
public
getEmbedImages() : bool
Return values
boolgetGenerateSheetNavigationBlock()
Get sheet index.
public
getGenerateSheetNavigationBlock() : bool
Return values
boolgetImagesRoot()
Get images root.
public
getImagesRoot() : string
Return values
stringgetIncludeCharts()
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
boolgetOrientation()
public
getOrientation() : string|null
Return values
string|nullgetPreCalculateFormulas()
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
boolgetSheetIndex()
Get sheet index.
public
getSheetIndex() : int|null
Return values
int|nullgetTableFormats()
public
getTableFormats() : bool
Return values
boolgetUseDiskCaching()
Get use disk caching where possible?
public
getUseDiskCaching() : bool
Return values
boolgetUseInlineCss()
Get use inline CSS?
public
getUseInlineCss() : bool
Return values
boolopenFileHandle()
Open file handle.
public
openFileHandle(resource|string $filename) : void
Parameters
- $filename : resource|string
save()
Save Spreadsheet 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
setBetterBoolean()
public
setBetterBoolean(bool $betterBoolean) : self
Parameters
- $betterBoolean : bool
Return values
selfsetConditionalFormatting()
public
setConditionalFormatting(bool $conditionalFormatting) : self
Parameters
- $conditionalFormatting : bool
Return values
selfsetEditHtmlCallback()
Set a callback to edit the entire HTML.
public
setEditHtmlCallback(callable|null $callback) : void
The callback must accept the HTML as string as first parameter, and it must return the edited HTML as string.
Parameters
- $callback : callable|null
setEmbedImages()
Set embed images.
public
setEmbedImages(bool $embedImages) : $this
Parameters
- $embedImages : bool
Return values
$thissetGenerateSheetNavigationBlock()
Set sheet index.
public
setGenerateSheetNavigationBlock(bool $generateSheetNavigationBlock) : $this
Parameters
- $generateSheetNavigationBlock : bool
-
Flag indicating whether the sheet navigation block should be generated or not
Return values
$thissetImagesRoot()
Set images root.
public
setImagesRoot(string $imagesRoot) : $this
Parameters
- $imagesRoot : string
Return values
$thissetIncludeCharts()
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
$thissetPreCalculateFormulas()
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
$thissetSheetIndex()
Set sheet index.
public
setSheetIndex(int $sheetIndex) : $this
Parameters
- $sheetIndex : int
-
Sheet index
Return values
$thissetTableFormats()
public
setTableFormats(bool $tableFormats) : self
Parameters
- $tableFormats : 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
$thissetUseInlineCss()
Set use inline CSS?
public
setUseInlineCss(bool $useInlineCss) : $this
Parameters
- $useInlineCss : bool
Return values
$thiswinFileToUrl()
Convert Windows file name to file protocol URL.
public
static winFileToUrl(string $filename[, bool $mpdf = false ]) : string
Parameters
- $filename : string
-
file name on local system
- $mpdf : bool = false
Return values
stringwriteAllSheets()
Write all sheets (resets sheetIndex to NULL).
public
writeAllSheets() : $this
Return values
$thischeckRtlAndLtr()
protected
checkRtlAndLtr() : void
maybeCloseFileHandle()
Close file handle only if we opened it ourselves.
protected
maybeCloseFileHandle() : void
processFlags()
protected
processFlags(int $flags) : void
Parameters
- $flags : int