Skip to content

Commit

Permalink
Fix Xlsx loaded an extra empty comment for each real comment
Browse files Browse the repository at this point in the history
Fixes #375
Closes #420
  • Loading branch information
xklid101 authored and PowerKiKi committed May 26, 2018
1 parent c723833 commit 7e9f43b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Subtotal 9 in a group that has other subtotals 9 exclude the totals of the other subtotals in the range - [#332](https://github.com/PHPOffice/PhpSpreadsheet/issues/332)
- `Helper\Html` support UTF-8 HTML input - [#444](https://github.com/PHPOffice/PhpSpreadsheet/issues/444)
- Xlsx loaded an extra empty comment for each real comment - [#375](https://github.com/PHPOffice/PhpSpreadsheet/issues/375)

## [1.2.1] - 2018-04-10

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ public function load($pFilename)

if (($column !== null) && ($row !== null)) {
// Set comment properties
$comment = $docSheet->getCommentByColumnAndRow((string) $column, $row + 1);
$comment = $docSheet->getCommentByColumnAndRow($column + 1, $row + 1);
$comment->getFillColor()->setRGB($fillColor);

// Parse style
Expand Down
44 changes: 44 additions & 0 deletions tests/PhpSpreadsheetTests/Functional/CommentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Functional;

use PhpOffice\PhpSpreadsheet\Spreadsheet;

class CommentsTest extends AbstractFunctional
{
public function providerFormats()
{
return [
['Html'],
['Xlsx'],
['Ods'],
];
}

/**
* Test load file with comment in sheet to load proper
* count of comments in correct coords.
*
* @dataProvider providerFormats
*
* @param $format
*/
public function testComments($format)
{
$spreadsheet = new Spreadsheet();

$spreadsheet->getActiveSheet()->getCell('E10')->setValue('Comment');
$spreadsheet->getActiveSheet()
->getComment('E10')
->getText()
->createText('Comment to test');

$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);

$commentsLoaded = $reloadedSpreadsheet->getSheet(0)->getComments();
self::assertCount(1, $commentsLoaded);

$commentCoordinate = key($commentsLoaded);
self::assertSame('E10', $commentCoordinate);
}
}

0 comments on commit 7e9f43b

Please sign in to comment.