Skip to content

Commit

Permalink
Process Comments in Sylk File
Browse files Browse the repository at this point in the history
Fixes issue PHPOffice#2276.
  • Loading branch information
oleibman committed Aug 22, 2021
1 parent 3c5750b commit 8ed6b20
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/PhpSpreadsheet/Reader/Slk.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ private function processCRecord(array $rowData, Spreadsheet &$spreadsheet, strin
case 'E':
$this->processFormula($rowDatum, $hasCalculatedValue, $cellDataFormula, $row, $column);

break;
case 'A':
$comment = substr($rowDatum, 1);
$columnLetter = Coordinate::stringFromColumnIndex((int) $column);
$spreadsheet->getActiveSheet()
->getComment("$columnLetter$row")
->getText()
->createText($comment);

break;
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Slk/SlkCommentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Slk;

use PhpOffice\PhpSpreadsheet\Reader\Slk;

class SlkCommentsTest extends \PHPUnit\Framework\TestCase
{
public function testComments(): void
{
$testbook = 'tests/data/Reader/Slk/issue.2276.slk';
$reader = new Slk();
$spreadsheet = $reader->load($testbook);
$sheet = $spreadsheet->getActiveSheet();
$comments = $sheet->getComments();
self::assertCount(2, $comments);
self::assertArrayHasKey('A1', $comments);
self::assertArrayHasKey('B2', $comments);
self::assertSame("Zeratul:\nEn Taro Adun!", $sheet->getComment('A1')->getText()->getPlainText());
self::assertSame("Arthas:\nFrostmourne Hungers.", $sheet->getComment('B2')->getText()->getPlainText());
$spreadsheet->disconnectWorksheets();
}
}
10 changes: 10 additions & 0 deletions tests/data/Reader/Slk/issue.2276.slk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ID;PWXL;N;E
P;PGeneral
F;P0;DG0G10;M320
B;Y3;X1;D0 0 9 0
C;Y1;X1;AZeratul: :En Taro Adun!
C;Y2;X2;AArthas: :Frostmourne Hungers.
C;Y1;X1;K1
C;Y1;X2;K2
C;Y2;X1;K3
E

0 comments on commit 8ed6b20

Please sign in to comment.