Skip to content

Commit

Permalink
add notes (old style comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
aVadim483 committed Jun 17, 2023
1 parent 87c35e7 commit ecfc3f9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Jump To:
* [Advanced Example](#advanced-example)
* [Height And Width](#height-and-width)
* [Define Named Ranges](#define-named-ranges)
* [Define Named Ranges](#define-named-ranges)
* [Workbook](/docs/01-workbook.md)
* [Workbook settings](/docs/01-workbook.md#workbook-settings)
* [Sets metadata of workbook](/docs/01-workbook.md#sets-metadata-of-workbook)
Expand Down Expand Up @@ -256,6 +257,23 @@ $excel->addNamedRange('Sheet1!A1:F5', 'A1_F5');

```

### Adding Notes

Notes are old style comments in Excel (notes on a light yellow background). You can add notes to any cells

```php

$sheet->writeCell('Text to A1');
$sheet->addNote('A1', 'This is a note for cell A1');

$sheet->writeCell('Text to B1')->addNote('This is a note for B1');
$sheet->writeTo('C4', 'Text to C4')->addNote('Note for C1');


$sheet->addNote('E4:F8', 'This note will added to E4');

```

## Do you want to support FastExcelWriter?

if you find this package useful you can support and donate to me for a cup of coffee:
Expand Down
2 changes: 1 addition & 1 deletion docs/04-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ $sheet->withRange('B4:D5')->applyBgColor('#cff')->applyBorderOuter(Style::BORDER
* applyVerticalAlign(string $verticalAlign)
* applyTextCenter()
* applyTextWrap(bool $textWrap)
* applyTextRotation(int $degrees)
* applyTextRotation(int $degrees) (thanks to @jarrod-colluco)

Returns to [README.md](/README.md)
25 changes: 18 additions & 7 deletions src/FastExcelWriter/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2316,18 +2316,29 @@ public function getNamedRanges(): array

/**
* @param string $cell
* @param string $comment
* @param string|null $comment
*
* @return $this
*/
public function addNote(string $cell, string $comment): Sheet
public function addNote(string $cell, ?string $comment = null): Sheet
{
$dimension = self::_rangeDimension($cell);
if (isset($dimension['cell1'])) {
if (func_num_args() === 1) {
$comment = $cell;
$rowIdx = $this->lastTouch['cell']['row_idx'];
$colIdx = $this->lastTouch['cell']['col_idx'];
$cell = Excel::cellAddress($rowIdx + 1, $colIdx + 1);
}
else {
$dimension = self::_rangeDimension($cell);
$cell = $dimension['cell1'];
$rowIdx = $dimension['rowIndex'];
$colIdx = $dimension['colIndex'];
}
if ($cell) {
$this->notes[] = [
'cell' => $dimension['cell1'],
'row_index' => $dimension['rowIndex'],
'col_index' => $dimension['colIndex'],
'cell' => $cell,
'row_index' => $rowIdx,
'col_index' => $colIdx,
'text' => $comment,
'style' => [
'width' => '96pt',
Expand Down

0 comments on commit ecfc3f9

Please sign in to comment.