Skip to content

Commit

Permalink
refactoring, upd docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aVadim483 committed Oct 11, 2024
1 parent 4cfc6ee commit cd2a126
Show file tree
Hide file tree
Showing 13 changed files with 4,653 additions and 762 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
## V.6.1

* Sheet::setRowStyle($rowNum, $style) - set style for row
* Sheet::setColStyle($colLetter, $style) - set style for column
* Sheet::setRowOptions(), Sheet::setColOptions(), Sheet::setRowStyles() and Sheet::setColStyles() are deprecated
* Sheet::setRowStyle($rowNum, $style) - set style for row (or row range)
* Sheet::setRowStyleArray($rowStyle) - set styles for rows (or row range)
* Sheet::setRowDataStyle($rowNum, $style)
* Sheet::setRowDataStyleArray($rowStyle)
* Sheet::setColStyle($colLetter, $style) - set style for column (or column range)
* Sheet::setColStyleArray($colStyles) - set style for column (or column range)
* Sheet::setColDataStyle($colLetter, $style)
* Sheet::setColDataStyleArray($colStyles)

## V.6.0

Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ This library is designed to be lightweight, super-fast and requires minimal memo
* Supports data validations

Jump To:
* [Changes in version 4](#changes-in-version-4)
* [Changes in version 6](#changes-in-version-6)
* [Changes in version 5](#changes-in-version-5)
* [Important changes in version 5.8](#important-changes-in-version-58)
* [Important changes in version 5.8](#important-changes-in-version-58)
* [Simple Example](#simple-example)
* [Advanced Example](#advanced-example)
* [Adding Notes](#adding-notes)
Expand Down Expand Up @@ -121,11 +121,17 @@ composer require avadim/fast-excel-writer

* Data Validation support

### Important changes in version 6.1
* ```Sheet::setRowOptions()```, ```Sheet::setColOptions()```, ```Sheet::setRowStyles()``` and ```Sheet::setColStyles()```
are deprecated, instead of them you should use other functions: ```setRowStyle()```, ```setRowStyleArray()```,
```setRowDataStyle()```, ```setRowDataStyleArray()```, ```setColStyle()```, ```setColStyleArray()```, ```setColDataStyle()```, ```setColDataStyleArray()```
* The behavior of the ```Sheet::setRowStyle()``` and ```Sheet::setColStyle()``` has changed, they now set styles for the entire row or column (even if they are empty)

## Changes In Version 5

* The general news is Chart support

## Important changes in version 5.8
### Important changes in version 5.8

Before v.5.8
```php
Expand Down Expand Up @@ -191,6 +197,7 @@ $excel->download('download.xlsx');
```

### Advanced Example

```php
use \avadim\FastExcelWriter\Excel;

Expand Down Expand Up @@ -231,16 +238,16 @@ $sheet
// The seconds way to set columns options
$sheet
// column and options
->setColOptions('A', ['format' => '@date', 'width' => 12])
->setColDataStyle('A', ['format' => '@date', 'width' => 12])
// column letter in lower case
->setColOptions('b', ['format' => '@text', 'width' => 24])
->setColDataStyle('b', ['format' => '@text', 'width' => 24])
// column can be specified by number
->setColOptions(3, ['format' => '0.00', 'width' => 15, 'color' => '#090'])
->setColDataStyle(3, ['format' => '0.00', 'width' => 15, 'color' => '#090'])
;

// The third way - all options in multilevel array (first level keys point to columns)
$sheet
->setColOptions([
->setColDataStyle([
'A' => ['format' => '@date', 'width' => 12],
'B' => ['format' => '@text', 'width' => 24],
'C' => ['format' => '0.00', 'width' => 15, 'color' => '#090'],
Expand Down
2 changes: 1 addition & 1 deletion demo/demo-v5-07-advanced-usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
$sheet->setColFormats([null, '@', '@', '@date', '0', '0.00', '@money', '@money']);

// Set style and width for specified column
$sheet->setColOptions('K', ['text-wrap' => true, 'width' => 32]);
$sheet->setColDataStyle('K', ['text-wrap' => true, 'width' => 32]);

// Set options for specified columns in the row
$cellStyles = ['I' => ['format' => '@percent'], 'j' => ['format' => '@money']];
Expand Down
5 changes: 3 additions & 2 deletions demo/demo-v5-09-datetime-formats.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
$sheet = $excel->getSheet();

$columns = [];
$colNum = 1;
foreach ($formats as $format) {
$columns[] = [
$columns[$colNum++] = [
'format' => $format,
'width' => 24,
];
}
$sheet->setColOptions($columns);
$sheet->setColDataStyleArray($columns);
$sheet->writeHeader($formats, ['font' => 'bold', 'text-align' => 'center', 'border' => 'thin']);

foreach ($data as $value) {
Expand Down
43 changes: 37 additions & 6 deletions docs/02-sheets.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ Note that in this case these styles will only be applied to those cells in the r

```php
// Write row data and set height
$rowOptions = [
$rowStyle = [
'fill-color' => '#fffeee',
'border' => 'thin',
'height' => 28,
];
$sheet->writeRow(['aaa', 'bbb', 'ccc'], $rowOptions);
$sheet->writeRow(['aaa', 'bbb', 'ccc'], $rowStyle);
```
Other way with the same result

Expand Down Expand Up @@ -137,31 +137,44 @@ $sheet->setRowHeight(1, 33);

```

You can set the style for the entire sheet row or only for those cells in the row where data is written.
```php
// Style are applied to the entire sheet row
$sheet->setRowStyle(3, ['height' = 20]);
$sheet->setRowStyle('2:5', ['font-color' = '#f00']);
$sheet->setRowStyleArray([3 => $style1, 5 => $style2]);

// Set the style only for non-empty cells in a row
$sheet->setRowDataStyle(3, ['height' = 20]);
$sheet->setRowDataStyle('2:5', ['font-color' = '#f00']);
$sheet->setRowDataStyleArray([3 => $style1, 5 => $style2]);
```

### Column's settings

Column widths can be set in several ways

```php
// Set width of column D to 24
$sheet->setColWidth('D', 24);
$sheet->setColOptions('D', ['width' => 24]);
$sheet->setColDataStyle('D', ['width' => 24]);
// Set auto width
$sheet->setColWidth('D', 'auto');
$sheet->setColWidthAuto('D');
$sheet->setColOptions('D', ['width' => 'auto']);
$sheet->setColDataStyle('D', ['width' => 'auto']);

// Set width of specific columns
$sheet->setColWidths(['B' => 10, 'C' => 'auto', 'E' => 30, 'F' => 40]);
// Set width of columns from 'A'
$sheet->setColWidths([10, 20, 30, 40], 24);

$colOptions = [
$colStyle = [
'B' => ['width' => 10],
'C' => ['width' => 'auto'],
'E' => ['width' => 30],
'F' => ['width' => 40],
];
$sheet->setColOptions($colOptions);
$sheet->setColDataStyleArray($colStyle);

```
You can define a minimal width of columns. Note that the minimum value has higher priority
Expand Down Expand Up @@ -190,6 +203,24 @@ $sheet->setColVisible(['B', 'E', 'H'], false);
// Show column E
$sheet->setColVisible('E', true);
```

You can set the style for the entire sheet column or only for those cells in the column where data is written.
```php
// Style are applied to the entire sheet column
$sheet->setColStyle('B', $style); // style for cells of column 'B'
$sheet->setColStyle(2, $style); // column 'B' has a number 2
$sheet->setColStyle('C:F', $style); // style for range of columns
$sheet->setColStyle(['A', 'B', 'C'], $style); // options for several columns 'A', 'B' and 'C'
$sheet->setColStyleArray(['B' => ['width' = 20], 'C' => ['font-color' = '#f00']]);

// Set the style only for non-empty cells in a column
$sheet->setColDataStyle('B', ['width' = 20]);
$sheet->setColDataStyle(2, ['width' = 20]);
$sheet->setColDataStyle('B:D', ['width' = 'auto']);
$sheet->setColDataStyle(['A', 'B', 'C'], $style);
$sheet->setColDataStyleArray(['B' => $style1, 'C' => $style2]);
```

### Group/outline rows and columns

Set group level for the specified rows
Expand Down
2 changes: 1 addition & 1 deletion docs/04-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ $sheet1->setColFormat('K', '@date');

```php
// Set style and width for specified column
$sheet1->setColOptions('K', ['text-wrap' => true, 'width' => 32]);
$sheet1->setColDataStyle('K', ['text-wrap' => true, 'width' => 32]);

// Set widths of columns from the first (A)
$sheet1->setColWidths([5, 16, 16, 'auto']);
Expand Down
Loading

0 comments on commit cd2a126

Please sign in to comment.