Skip to content

Permit Max Column for Row Breaks #3345

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

Merged
merged 5 commits into from
Feb 11, 2023
Merged

Conversation

oleibman
Copy link
Collaborator

@oleibman oleibman commented Feb 4, 2023

Fix #3143. Page break was dropped. Difference between good and bad was the use of attribute max in brk tag in the good spreadsheet. However, max was not required in a similar spreadsheet. So the reason for the problem isn't completely explained, although the likeliest explanation seems to be an Excel bug. Nevertheless, it can't really hurt to capture the max value on read (if present) and generate it on write. This resolves the issue. User is also permitted to specify max column when setting a row break programatically. Documentation is updated.

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?

Provide an explanation of why this change is needed, with links to any Issues (if appropriate).
If this is a bugfix or a new feature, and there are no existing Issues, then please also create an issue that will make it easier to track progress with this PR.

Fix PHPOffice#3143. Page break was dropped. Difference between good and bad was the use of attribute `max` in `brk` tag in the good spreadsheet. However, `max` was *not* required in a similar spreadsheet. So the reason for the problem isn't completely explained. Nevertheless, it can't really hurt to capture the `max` value on read (if present) and generate it on write. This resolves the issue. User is also permitted to specify max column when setting a row break programatically. I am not yet in position to document when that might be a good idea.
Not a problem on my Windows system.
@oleibman
Copy link
Collaborator Author

oleibman commented Feb 6, 2023

I have tested further, using PhpSpreadsheet code to emulate the problem spreadsheet, and I am quite certain that the only difference between a spreadsheet which appears as expected and one which doesn't is the brk max attribute. This convinces me that Excel is acting strangely when faced with a row page break inside a defined print area. Bug? Feature? Who knows? At any rate, this result tells me that we should proceed with this PR. It does not convince me that it is always safe to add the max attribute, nor that the value should always be 16,383, but I can at least document when this should be done and suggest that as a reasonable value to use. I will update this PR with a documentation change and additional tests.

@oleibman
Copy link
Collaborator Author

oleibman commented Feb 6, 2023

BTW, LibreOffice handles the printing correctly whether or not max is specified on brk.

Change is necessitated by probable Excel bug.
I kind of shoe-horned it in. Better to create a new PageBreak class, which will make it easier to accomodate any future surprises about page break handling. The only difficulty with the new approach is making sure getBreaks maintains backwards compatibility. New tests will ensure that.
@oleibman oleibman merged commit 4e09fd4 into PHPOffice:master Feb 11, 2023
@oleibman oleibman deleted the issue3143 branch March 2, 2023 03:41
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this pull request Apr 22, 2025
Fix PHPOffice#1275, which had been closed as stale, and is now reopened pending the implementation of this PR. If there is a page break inside a defined print area, Excel may not render the print correctly unless the xml `brk` tag contains a `max` attribute. Libre Office renders it correctly. This seems like a bug in Excel (https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/b32ae11b-dee7-4dcb-9b46-a0feb32ce94f states that Office ignores min and max). PR PHPOffice#3345 (issue PHPOffice#3143) already addressed this problem by allowing the user to explicitly specify a `max` property in the PageBreak object. This PR eliminates the need for the user to make use of that kludge, by adding `max` to the xml whenever a page break is specified on a sheet with a defined print area. Xlsx Reader will now ignore the `max` attribute for row breaks, since it is no longer needed; it already ignores it for column breaks. The user may still set the `max` property if desired, just in case the new treatment is not adequate (I have not found a case where that is true). Two existing unit tests are very marginally changed because of this PR.
@oleibman oleibman mentioned this pull request Apr 22, 2025
11 tasks
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.

Generated Excel file loses page breaks when prininting area does not start in the first column
1 participant