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

Fix for Issue 2029 (Invalid Cell Coordinate A-1) #2032

Merged
merged 5 commits into from
Apr 29, 2021

Conversation

oleibman
Copy link
Collaborator

Fix for #2029. When Html Reader encounters an embedded table, it tries to shift it up a row. It obviously should not attempt to shift it above row 1. @danmodini reported the problem, and suggests the correct solution. This PR implements that and adds a test case.

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

Fix for PHPOffice#2021. When Html Reader encounters an embedded table, it tries to shift it up a row. It obviously should not attempt to shift it above row 1. @danmodini reported the problem, and suggests the correct solution. This PR implements that and adds a test case.
Performing some additional testing, I found that Html Reader cannot handle inline column width or row height set in points rather than pixels (and HTML writer with useInlineCss generates these values in points). It also doesn't handle border style when the border width (which it ignores) is omitted. Fixed and added tests.
@@ -878,14 +878,14 @@ private function applyInlineStyle(&$sheet, $row, $column, $attributeArray): void

case 'width':
$sheet->getColumnDimension($column)->setWidth(
(float) str_replace('px', '', $styleValue)
(float) str_replace(['px', 'pt'], '', $styleValue)
Copy link
Member

Choose a reason for hiding this comment

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

I have half of a helper class that covers a wide range of the UoM that can be applied in html styles, with conversion factors for import to Spreadsheet styles... but this will work well enough for the moment... it's the relative units that are a real annoyance, because we can't adjudge 50% accurately, as we don't know 50% of what? I'll do that as a separate PR at some point though

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would be really helpful, especially because Excel widths and heights aren't well documented. They aren't pixels, or points, or twips, or ... I know the default column width in Excel units and in pixels, but I haven't had time to establish whether there is a linear relationship between them. The Html writer and reader probably make things too wide or too narrow because of this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Didn't really mean non-linear above - it is linear, but it depends on the font. Which may be too sophisticated to try to emulate (as with your 50% comment). But I think it translates better to expressing the unit as ems rather than points or pixels.

@MarkBaker MarkBaker merged commit cc5c020 into PHPOffice:master Apr 29, 2021
@oleibman oleibman deleted the issue2029 branch July 1, 2021 15:46
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