public function PHPExcel_Writer_HTML::buildCSS in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php \PHPExcel_Writer_HTML::buildCSS()
* Build CSS styles * *
Parameters
boolean $generateSurroundingHTML Generate surrounding HTML style? (html { }): * @return array * @throws PHPExcel_Writer_Exception
3 calls to PHPExcel_Writer_HTML::buildCSS()
- PHPExcel_Writer_HTML::generateStyles in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Writer/ HTML.php - * Generate CSS styles * *
- PHPExcel_Writer_HTML::save in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Writer/ HTML.php - * Save PHPExcel to file * *
- PHPExcel_Writer_PDF_Core::prepareForSave in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Writer/ PDF/ Core.php - Save PHPExcel to PDF file, pre-save
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Writer/ HTML.php, line 720
Class
- PHPExcel_Writer_HTML
- PHPExcel_Writer_HTML
Code
public function buildCSS($generateSurroundingHTML = true) {
// PHPExcel object known?
if (is_null($this->_phpExcel)) {
throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
}
// Cached?
if (!is_null($this->_cssStyles)) {
return $this->_cssStyles;
}
// Ensure that spans have been calculated
if (!$this->_spansAreCalculated) {
$this
->_calculateSpans();
}
// Construct CSS
$css = array();
// Start styles
if ($generateSurroundingHTML) {
// html { }
$css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif';
$css['html']['font-size'] = '11pt';
$css['html']['background-color'] = 'white';
}
// table { }
$css['table']['border-collapse'] = 'collapse';
if (!$this->_isPdf) {
$css['table']['page-break-after'] = 'always';
}
// .gridlines td { }
$css['.gridlines td']['border'] = '1px dotted black';
$css['.gridlines th']['border'] = '1px dotted black';
// .b {}
$css['.b']['text-align'] = 'center';
// BOOL
// .e {}
$css['.e']['text-align'] = 'center';
// ERROR
// .f {}
$css['.f']['text-align'] = 'right';
// FORMULA
// .inlineStr {}
$css['.inlineStr']['text-align'] = 'left';
// INLINE
// .n {}
$css['.n']['text-align'] = 'right';
// NUMERIC
// .s {}
$css['.s']['text-align'] = 'left';
// STRING
// Calculate cell style hashes
foreach ($this->_phpExcel
->getCellXfCollection() as $index => $style) {
$css['td.style' . $index] = $this
->_createCSSStyle($style);
$css['th.style' . $index] = $this
->_createCSSStyle($style);
}
// Fetch sheets
$sheets = array();
if (is_null($this->_sheetIndex)) {
$sheets = $this->_phpExcel
->getAllSheets();
}
else {
$sheets[] = $this->_phpExcel
->getSheet($this->_sheetIndex);
}
// Build styles per sheet
foreach ($sheets as $sheet) {
// Calculate hash code
$sheetIndex = $sheet
->getParent()
->getIndex($sheet);
// Build styles
// Calculate column widths
$sheet
->calculateColumnWidths();
// col elements, initialize
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($sheet
->getHighestColumn()) - 1;
$column = -1;
while ($column++ < $highestColumnIndex) {
$this->_columnWidths[$sheetIndex][$column] = 42;
// approximation
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = '42pt';
}
// col elements, loop through columnDimensions and set width
foreach ($sheet
->getColumnDimensions() as $columnDimension) {
if (($width = PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension
->getWidth(), $this->_defaultFont)) >= 0) {
$width = PHPExcel_Shared_Drawing::pixelsToPoints($width);
$column = PHPExcel_Cell::columnIndexFromString($columnDimension
->getColumnIndex()) - 1;
$this->_columnWidths[$sheetIndex][$column] = $width;
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt';
if ($columnDimension
->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse';
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['*display'] = 'none';
// target IE6+7
}
}
}
// Default row height
$rowDimension = $sheet
->getDefaultRowDimension();
// table.sheetN tr { }
$css['table.sheet' . $sheetIndex . ' tr'] = array();
if ($rowDimension
->getRowHeight() == -1) {
$pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->_phpExcel
->getDefaultStyle()
->getFont());
}
else {
$pt_height = $rowDimension
->getRowHeight();
}
$css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt';
if ($rowDimension
->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden';
}
// Calculate row heights
foreach ($sheet
->getRowDimensions() as $rowDimension) {
$row = $rowDimension
->getRowIndex() - 1;
// table.sheetN tr.rowYYYYYY { }
$css['table.sheet' . $sheetIndex . ' tr.row' . $row] = array();
if ($rowDimension
->getRowHeight() == -1) {
$pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->_phpExcel
->getDefaultStyle()
->getFont());
}
else {
$pt_height = $rowDimension
->getRowHeight();
}
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'] = $pt_height . 'pt';
if ($rowDimension
->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['visibility'] = 'hidden';
}
}
}
// Cache
if (is_null($this->_cssStyles)) {
$this->_cssStyles = $css;
}
// Return
return $css;
}