Skip to content

Commit

Permalink
add: Sheet::applyFillGradient()
Browse files Browse the repository at this point in the history
  • Loading branch information
aVadim483 committed Jan 2, 2025
1 parent 0131e9c commit 70332f7
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* New methods Sheet::getCurrentRow(), Sheet::getCurrentCol(), Sheet::getCurrentCell()
* New methods Sheet::applyIndentLeft(), Sheet::applyIndentRight(), Sheet::applyIndentDistributed()
* New method Sheet::applyFillGradient()
* Method Sheet::addImage() has been updated -- Add an image from a local file, URL, or base64 image string
* Data can be passed to a cell as a function
* Fixed page margins
Expand Down
165 changes: 157 additions & 8 deletions docs/92-api-class-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* [__construct()](#__construct) -- Sheet constructor
* [setActiveCell()](#setactivecell) -- Set active cell
* [addCellStyle()](#addcellstyle)
* [addCellStyle()](#addcellstyle) -- Add additional styles to a cell
* [addChart()](#addchart) -- Add chart object to the specified range of cells
* [addDataValidation()](#adddatavalidation) -- Add data validation object to the specified range of cells
* [addImage()](#addimage) -- Add image to the sheet from local file, URL or image string in base64
Expand All @@ -27,15 +27,18 @@
* [allowSelectLockedCells()](#allowselectlockedcells) -- Selection of locked cells should be allowed when the sheet is protected
* [allowSelectUnlockedCells()](#allowselectunlockedcells) -- Selection of unlocked cells should be allowed when the sheet is protected
* [allowSort()](#allowsort) -- Sorting should be allowed when the sheet is protected
* [applyBgColor()](#applybgcolor)
* [applyAlignLeft()](#applyalignleft) -- Apply left alignment to content
* [applyAlignRight()](#applyalignright) -- Apply right alignment to content
* [applyBgColor()](#applybgcolor) -- Alias of 'applyFillColor()'
* [applyBorder()](#applyborder) -- Sets all borders style
* [applyBorderBottom()](#applyborderbottom)
* [applyBorderLeft()](#applyborderleft)
* [applyBorderRight()](#applyborderright)
* [applyBorderTop()](#applybordertop)
* [applyColor()](#applycolor) -- Alias of 'setFontColor()'
* [applyDataValidation()](#applydatavalidation)
* [applyFillColor()](#applyfillcolor) -- Alias of 'backgroundColor()'
* [applyFillColor()](#applyfillcolor) -- Fill background color
* [applyFillGradient()](#applyfillgradient) -- Fill background by gradient
* [applyFont()](#applyfont)
* [applyFontColor()](#applyfontcolor)
* [applyFontName()](#applyfontname)
Expand All @@ -47,6 +50,9 @@
* [applyFontStyleUnderline()](#applyfontstyleunderline)
* [applyFormat()](#applyformat)
* [applyHide()](#applyhide)
* [applyIndentDistributed()](#applyindentdistributed)
* [applyIndentLeft()](#applyindentleft)
* [applyIndentRight()](#applyindentright)
* [applyInnerBorder()](#applyinnerborder)
* [applyNamedRange()](#applynamedrange)
* [applyOuterBorder()](#applyouterborder)
Expand Down Expand Up @@ -89,7 +95,10 @@
* [setColWidth()](#setcolwidth) -- Set width of single or multiple column(s)
* [setColWidthAuto()](#setcolwidthauto) -- Set width of single or multiple column(s)
* [setColWidths()](#setcolwidths) -- Setting a multiple column's width
* [getCurrentCell()](#getcurrentcell) -- Returns address of the current cell
* [getCurrentCol()](#getcurrentcol) -- Returns current column letter
* [getCurrentColId()](#getcurrentcolid)
* [getCurrentRow()](#getcurrentrow) -- Returns current row number
* [getCurrentRowId()](#getcurrentrowid)
* [getDataValidations()](#getdatavalidations)
* [setDefaultFont()](#setdefaultfont)
Expand Down Expand Up @@ -227,7 +236,7 @@ _Set active cell_
```php
public function addCellStyle(string $cellAddr, array $style): Sheet
```

_Add additional styles to a cell_

### Parameters

Expand Down Expand Up @@ -606,18 +615,49 @@ _Sorting should be allowed when the sheet is protected_

---

## applyBgColor()
## applyAlignLeft()

---

```php
public function applyAlignLeft(): Sheet
```
_Apply left alignment to content_

### Parameters

_None_

---

## applyAlignRight()

---

```php
public function applyBgColor(string $color): Sheet
public function applyAlignRight(): Sheet
```
_Apply right alignment to content_

### Parameters

_None_

---

## applyBgColor()

---

```php
public function applyBgColor(string $color, ?string $pattern = null): Sheet
```
_Alias of 'applyFillColor()'_

### Parameters

* `string $color`
* `string|null $pattern`

---

Expand Down Expand Up @@ -740,13 +780,32 @@ public function applyDataValidation(avadim\FastExcelWriter\DataValidation\DataVa
---

```php
public function applyFillColor(string $color): Sheet
public function applyFillColor(string $color, ?string $pattern = null): Sheet
```
_Alias of 'backgroundColor()'_
_Fill background color_

### Parameters

* `string $color`
* `string|null $pattern`

---

## applyFillGradient()

---

```php
public function applyFillGradient(string $color1, string $color2,
?int $degree = null): Sheet
```
_Fill background by gradient_

### Parameters

* `string $color1`
* `string $color2`
* `int|null $degree`

---

Expand Down Expand Up @@ -920,6 +979,51 @@ public function applyHide(?bool $hide = true): Sheet

---

## applyIndentDistributed()

---

```php
public function applyIndentDistributed(int $indent): Sheet
```


### Parameters

* `int $indent`

---

## applyIndentLeft()

---

```php
public function applyIndentLeft(int $indent): Sheet
```


### Parameters

* `int $indent`

---

## applyIndentRight()

---

```php
public function applyIndentRight(int $indent): Sheet
```


### Parameters

* `int $indent`

---

## applyInnerBorder()

---
Expand Down Expand Up @@ -1652,6 +1756,36 @@ $sheet->setColWidths(['B' => 10, 'C' => 'auto', 'E' => 30, 'F' => 40]);
```


---

## getCurrentCell()

---

```php
public function getCurrentCell(): string
```
_Returns address of the current cell_

### Parameters

_None_

---

## getCurrentCol()

---

```php
public function getCurrentCol(): string
```
_Returns current column letter_

### Parameters

_None_

---

## getCurrentColId()
Expand All @@ -1663,6 +1797,21 @@ public function getCurrentColId(): int
```


### Parameters

_None_

---

## getCurrentRow()

---

```php
public function getCurrentRow(): int
```
_Returns current row number_

### Parameters

_None_
Expand Down
40 changes: 35 additions & 5 deletions src/FastExcelWriter/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2885,6 +2885,8 @@ public function setCellStyle(string $cellAddress, $style, ?bool $mergeStyles = f
}

/**
* Add additional styles to a cell
*
* @param string $cellAddr
* @param array $style
*
Expand Down Expand Up @@ -4830,27 +4832,51 @@ public function applyColor(string $color): Sheet
}

/**
* Alias of 'backgroundColor()'
* Fill background color
*
* @param string $color
* @param string|null $pattern
*
* @return $this
*/
public function applyFillColor(string $color): Sheet
public function applyFillColor(string $color, ?string $pattern = null): Sheet
{
$this->_setStyleOptions([], 'fill', ['fill-color' => $color]);
$this->_setStyleOptions([], 'fill', ['fill-color' => $color, 'fill-pattern' => $pattern ?: 'solid']);

return $this;
}

/**
* Alias of 'applyFillColor()'
*
* @param string $color
* @param string|null $pattern
*
* @return $this
*/
public function applyBgColor(string $color): Sheet
public function applyBgColor(string $color, ?string $pattern = null): Sheet
{
return $this->applyFillColor($color);
return $this->applyFillColor($color, $pattern);
}

/**
* Fill background by gradient
*
* @param string $color1
* @param string $color2
* @param int|null $degree
* @return $this
*/
public function applyFillGradient(string $color1, string $color2, ?int $degree = null): Sheet
{
$this->_setStyleOptions([], 'fill', [
'fill-pattern' => Style::FILL_GRADIENT_LINEAR,
'fill-gradient-start' => $color1,
'fill-gradient-end' => $color2,
'fill-gradient-degree' => $degree ?: 0,
]);

return $this;
}

/**
Expand Down Expand Up @@ -4893,6 +4919,8 @@ public function applyTextCenter(): Sheet
}

/**
* Apply left alignment to content
*
* @return $this
*/
public function applyAlignLeft(): Sheet
Expand All @@ -4901,6 +4929,8 @@ public function applyAlignLeft(): Sheet
}

/**
* Apply right alignment to content
*
* @return $this
*/
public function applyAlignRight(): Sheet
Expand Down
22 changes: 22 additions & 0 deletions src/FastExcelWriter/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ class Style

public const FILL_COLOR = 'fill-color';

const FILL_SOLID = 'solid';
const FILL_GRADIENT = 'linear';
const FILL_GRADIENT_LINEAR = 'linear';

public const FILL_PATTERN_DARKDOWN = 'darkDown';
public const FILL_PATTERN_DARKGRAY = 'darkGray';
public const FILL_PATTERN_DARKGRID = 'darkGrid';
public const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal';
public const FILL_PATTERN_DARKTRELLIS = 'darkTrellis';
public const FILL_PATTERN_DARKUP = 'darkUp';
public const FILL_PATTERN_DARKVERTICAL = 'darkVertical';
public const FILL_PATTERN_GRAY0625 = 'gray0625';
public const FILL_PATTERN_GRAY125 = 'gray125';
public const FILL_PATTERN_LIGHTDOWN = 'lightDown';
public const FILL_PATTERN_LIGHTGRAY = 'lightGray';
public const FILL_PATTERN_LIGHTGRID = 'lightGrid';
public const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal';
public const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis';
public const FILL_PATTERN_LIGHTUP = 'lightUp';
public const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical';
public const FILL_PATTERN_MEDIUMGRAY = 'mediumGray';

public const BORDER = 'border';

public const BORDER_SIDE = 1;
Expand Down
Loading

0 comments on commit 70332f7

Please sign in to comment.