Skip to content

Commit

Permalink
Update Style-Attributes example
Browse files Browse the repository at this point in the history
  • Loading branch information
yidas committed Nov 13, 2018
1 parent 1edcc2f commit 3436ce0
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 49 deletions.
66 changes: 43 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ OUTLINE
- [setSheet()](#setsheet)
- [getSheet()](#getsheet)
- [Map of Coordinates & Ranges](#multiple-sheets)
- [Style Attribute](#style-attribute)
- [Style Attributes](#style-attributes)
- [Columns Format](#columns-format)
- [Cells Format](#cells-format)
- [All Cells Format](#all-cells-format)
- [setStyle()](#setstyle)
- [setWrapText()](#setwraptext)
- [setAutoSize()](#setautosize)
Expand Down Expand Up @@ -472,34 +472,54 @@ sn range: A1:A2
All range: A1:E4
```

### Style Attribute
### Style Attributes

The style attribute could be set on a [single cell](#addrow), a [single row](#addrow) or even a [range of cells](#setstyle).

* `style`: a attribute refers to `applyFromArray()` for styling

```php
\yidas\phpSpreadsheet\Helper::newSpreadsheet()
->addRow(['Percentage', '10%',
['value'=>'content', 'style'=>
[
'font' => [
'bold' => true,
'color' => ['argb' => 'FFFF0000']
],
'alignment' => ['horizontal' => 'right'],
'borders' => [
'top' => ['borderStyle' => 'thin'],
],
'fill' => [
'fillType' => 'linear',
'rotation' => 90,
'startColor' => ['argb' => 'FFA0A0A0'],
'endColor' => ['argb' => 'FFFFFFFF'],
],
]
]
// Each cell with each style attributes
->addRow([
'Percentage',
'10%',
['value'=>'content', 'style'=> [
'font' => [
'bold' => true,
'color' => ['argb' => 'FFFF0000']
],
'alignment' => ['horizontal' => 'right'],
'borders' => [
'top' => ['borderStyle' => 'thin'],
],
'fill' => [
'fillType' => 'linear',
'rotation' => 90,
'startColor' => ['argb' => 'FFA0A0A0'],
'endColor' => ['argb' => 'FFFFFFFF'],
],
]],
['value'=>'10000', 'style'=> [
'numberFormat' => [
'formatCode' => '#,##0',
],
]],
])
// Row with thousands separator format style
->addRow(['1000', '2000', '3000', '4000'], ['style' => [
'numberFormat' => [
// const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00';
'formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
],
]])
// Row with percentage format style
->addRow(['0.1', '0.15', '0.3145', '0.855'], ['style' => [
'numberFormat' => [
// const FORMAT_PERCENTAGE_00 = '0.00%';
'formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00,
],
]])
->output();
```

Expand All @@ -521,7 +541,7 @@ The options for each cell data:
->output('My Excel');
```

### Cells Format
### All Cells Format

This section focuses on applying all actived cells or ranged cells on the sheet, not just effecting single cell, row or column.

Expand Down
26 changes: 0 additions & 26 deletions demo/cell-style.php

This file was deleted.

46 changes: 46 additions & 0 deletions demo/style-attributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

require __DIR__ . '/_config.php';

\yidas\phpSpreadsheet\Helper::newSpreadsheet()
// Each cell with each style attributes
->addRow([
'Percentage',
'10%',
['value'=>'content', 'style'=> [
'font' => [
'bold' => true,
'color' => ['argb' => 'FFFF0000']
],
'alignment' => ['horizontal' => 'right'],
'borders' => [
'top' => ['borderStyle' => 'thin'],
],
'fill' => [
'fillType' => 'linear',
'rotation' => 90,
'startColor' => ['argb' => 'FFA0A0A0'],
'endColor' => ['argb' => 'FFFFFFFF'],
],
]],
['value'=>'10000', 'style'=> [
'numberFormat' => [
'formatCode' => '#,##0',
],
]],
])
// Row with thousands separator format style
->addRow(['1000', '2000', '3000', '4000'], ['style' => [
'numberFormat' => [
// const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00';
'formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
],
]])
// Row with percentage format style
->addRow(['0.1', '0.15', '0.3145', '0.855'], ['style' => [
'numberFormat' => [
// const FORMAT_PERCENTAGE_00 = '0.00%';
'formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00,
],
]])
->output();

0 comments on commit 3436ce0

Please sign in to comment.