Styling with PHPExcel methods
It’s possible to style the sheets and specific cells with help of PHPExcel methods. This package includes a lot of shortcuts (see export documentation), but also always the use of the native methods.
// Set background color for a specific cell
$sheet->getStyle('A1')->applyFromArray(array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FF0000')
)
));
Using HTML tags
Most of the HTML tags are supported.
<html>
<!-- Headings -->
<td><h1>Big title</h1></td>
<!-- Bold -->
<td><b>Bold cell</b></td>
<td><strong>Bold cell</strong></td>
<!-- Italic -->
<td><i>Italic cell</i></td>
<!-- Images -->
<td><img src="img.jpg" /></td>
</html>
Inside the view.php
config you can change how these tags will be interpreted by Excel by default.
Using HTML attributes
Some of the basic styling can be done with HTML attributes.
<html>
<!-- Horizontal alignment -->
<td align="right">Big title</td>
<!-- Vertical alignment -->
<td valign="middle">Bold cell</td>
<!-- Rowspan -->
<td rowspan="3">Bold cell</td>
<!-- Colspan -->
<td colspan="6">Italic cell</td>
<!-- Width -->
<td width="100">Cell with width of 100</td>
<!-- Height -->
<td height="100">Cell with height of 100</td>
</html>
Styling through inline-styles
It’s possible to use inline styles inside your view files. Most of the general styles are supported.
<html>
<!-- Cell with black background -->
<td style="background-color: #000000;">Cell</td>
</html>
Inside the reference guide you can find a list of supported styles.
Styling through external CSS file
Styling can be done through an external CSS file.
External css file:
#cell {
background-color: #000000;
color: #ffffff;
}
.cell {
background-color: #000000;
color: #ffffff;
}
tr td {
background-color: #ffffff;
}
tr > td {
border-bottom: 1px solid #000000;
}
Table:
<html>
{{ HTML::style('css/table.css') }}
<!-- Cell styled with class -->
<td class="cell">Cell</td>
<!-- Cell styled with ID -->
<td id="cell">Cell</td>
</html>
Available file properties
Properties that can be set with $excel->set{$property}()
Property name |
---|
creator |
lastModifiedBy |
title |
description |
subject |
keywords |
category |
manager |
company |
Available sheet properties
Properties that can be set with $sheet->set{$property}()
Property name | Possible value |
---|---|
orientation | string |
paperSize | integer |
scale | integer |
fitToPage | boolean |
fitToHeight | boolean |
fitToWidth | boolean |
columnsToRepeatAtLeft | array |
rowsToRepeatAtTop | array |
horizontalCentered | boolean |
verticalCentered | boolean |
printArea | range |
firstPageNumber | integer |
Available CSS styles
Styles that can be used inside an external CSS file or as inline CSS.
Style name | Example Value |
---|---|
background(-color) | #000000 |
color | #FFFFFF |
font-weight | bold |
font-style | italic |
font-weight | bold |
font-size | 20px |
font-family | Open Sans |
text-decoration | underline |
text-align | center |
vertical-align | middle |
border(-*) | 1px dashed #CCC |
width | 100(px) |
height | 1100(px) |
Available border styles
Style name | PHPExcel class reference |
---|---|
none | PHPExcel_Style_Border::BORDER_NONE |
dashDot | PHPExcel_Style_Border::BORDER_DASHDOT |
dashDotDot | PHPExcel_Style_Border::BORDER_DASHDOTDOT |
dashed | PHPExcel_Style_Border::BORDER_DASHED |
dotted | PHPExcel_Style_Border::BORDER_DOTTED |
double | PHPExcel_Style_Border::BORDER_DOUBLE |
hair | PHPExcel_Style_Border::BORDER_HAIR |
medium | PHPExcel_Style_Border::BORDER_MEDIUM |
mediumDashDot | PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT |
mediumDashDotDot | PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT |
mediumDashed | PHPExcel_Style_Border::BORDER_MEDIUMDASHED |
slantDashDot | PHPExcel_Style_Border::BORDER_SLANTDASHDOT |
thick | PHPExcel_Style_Border::BORDER_THICK |
thin | PHPExcel_Style_Border::BORDER_THIN |
Available column formatting
Format name | PHPExcel class reference |
---|---|
General | PHPExcel_Style_NumberFormat::FORMAT_GENERAL |
@ | PHPExcel_Style_NumberFormat::FORMAT_TEXT |
0 | PHPExcel_Style_NumberFormat::FORMAT_NUMBER |
0.00 | PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00 |
#,##0.00 | PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1 |
#,##0.00_- | PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2 |
0% | PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE |
0.00% | PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00 |
yyyy-mm-dd | PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2 |
yy-mm-dd | PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD |
dd/mm/yy | PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY |
d/m/y | PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH |
d-m-y | PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS |
d-m | PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS |
m-y | PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS |
mm-dd-yy | PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14 |
d-mmm-yy | PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15 |
d-mmm | PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16 |
mmm-yy | PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17 |
m/d/yy h:mm | PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22 |
d/m/y h:mm | PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME |
h:mm AM/PM | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1 |
h:mm:ss AM/PM | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2 |
h:mm | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3 |
h:mm:ss | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 |
mm:ss | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5 |
h:mm:ss | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6 |
i:s.S | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7 |
h:mm:ss;@ | PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8 |
yy/mm/dd;@ | PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH |
“$”#,##0.00_- | PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE |
$#,##0_- | PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD |
[$EUR ]#,##0.00_- | PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE |
Closures
Method | Closure class |
---|---|
create() | Maatwebsite\Excel\Writers\LaravelExcelWriter |
load() | Maatwebsite\Excel\Readers\LaravelExcelReader |
batch | Maatwebsite\Excel\Readers\Batch |
sheet() | Maatwebsite\Excel\Classes\LaravelExcelWorksheet |
cells() | Maatwebsite\Excel\Writers\CellWriter |
row() | Maatwebsite\Excel\Writers\CellWriter |
Comments