Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support justifyLastLine #4373

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

YoheiZuho
Copy link

@YoheiZuho YoheiZuho commented Feb 18, 2025

This is:

  • a bugfix
  • a new feature
  • refactoring
  • additional unit tests

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
  • Documentation is updated as necessary

Why this change is needed?

justifyLastLine” is a flag used for the ‘Justify Distributed’ option, which is enabled only when the value of ‘Horizontal’ in the EXCEL setting ‘FormatCells’ is ‘Distributed’. When the option is enabled, an indent of a certain width is added before and after the text in the cell.
This option is often used in Japanese-speaking countries.

@oleibman
Copy link
Collaborator

You will need to fix the Phpstan problems and the unit tests that broke as a result of your change. Then you need to make sure that the new property in Alignment is used when calculating the alignment hash code. Then you need to add some tests to demonstrate that your change is working - at a minimum, set the new property in some cell on a spreadsheet (and leave it unset in other cells), write out the spreadsheet, read it back in, and confirm that the property is set or not as desired.

@YoheiZuho
Copy link
Author

I'd fix the Phpstan problems and the unit tests.

@oleibman
Copy link
Collaborator

Good work on correcting the earlier problems. You still need to include the new field when generating the hash code for Alignment, and to add unit test(s).

@YoheiZuho
Copy link
Author

You still need to include the new field when generating the hash code for Alignment, and to add unit test(s).

Excuse me, but which file should I add the test to?

@@ -265,6 +265,8 @@ public function readAlignmentStyle(Alignment $alignment, SimpleXMLElement $align
if ($horizontal !== '') {
$alignment->setHorizontal($horizontal);
}
$justifyLastLine = (string) $this->getAttribute($alignmentXml, 'justifyLastLine');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right. Because justifyLastLine can be null as well as true/false, if justifyLastLine isn't in the Xml, you should leave it as its default property. Your code will set it to false. It probably doesn't make a difference to the end result, but we strive to be "correct".

@@ -37,6 +37,7 @@ public function testNonDefaultAlign(): void
$rsheet = $reloadedSpreadsheet->getActiveSheet();
$expected1 = [
'horizontal' => 'center',
'justifyLastLine' => false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably be affected by the change I suggested above to Reader/Xlsx/Styles.

@@ -78,6 +79,7 @@ public function testDefaultAlign(): void
$rsheet = $reloadedSpreadsheet->getActiveSheet();
$expected1 = [
'horizontal' => 'general',
'justifyLastLine' => false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably be affected by the change I suggested above to Reader/Xlsx/Styles.

$sheet = $this->spreadsheet->getActiveSheet();
$cell1 = $sheet->getCell('A1');
$cell1->setValue('ABC');
$cell1->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your test is not doing enough (or you want to add an additional test in Reader/Xlsx). We want to write and then read the spreadsheet to prove that both Write and Read handle the new attribute correctly. Look for examples of this by searching for "writeAndReload" in the PhpSpreadsheetTests Reader/Xlsx directory.

@@ -475,6 +512,7 @@ public function getHashCode(): string

return md5(
$this->horizontal
. $this->justifyLastLine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another case where the 3-pronged value will cause problems. Probably change this to:

. (($this->justifyLastLine === null) ? 'null' : ($this->justifyLastLine ? 't' : 'f'))

@oleibman
Copy link
Collaborator

Despite the number of changes I've requested, you're in pretty good shape. I expect this will be ready to go soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants