-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
The exact autosize does not work correctly #3626
Comments
Some extra information I found out trying to debug the bug. Cell B1 detects that the text width is 96px (correct) but then determines that the column width should be 140px. If I adjust the column size in Excel (double click) it stays at 109px. |
It seems that if (!$approximate) {
try {
$columnWidthAdjust = ceil(
self::getTextWidthPixelsExact(
str_repeat('n', 1 * (($filterAdjustment ? 3 : 1) + ($indentAdjustment * 2))),
$font,
0
) * 1.07
);
// Width of text in pixels excl. padding
// and addition because Excel adds some padding, just use approx width of 'n' glyph
$columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation) + $columnWidthAdjust; It does this for Approximate as well, but that's not the case in hand, and it is more justifiable for Approximate than Exact. At any rate, if I zero out |
Fix PHPOffice#3626. User felt that Exact setting of column width should not add padding. In order to avoid making this a breaking change, I am adding a new boolean property `usePaddingForExact` with setter and getter to Shared/Font; default is false (current behavior).
Hi, I tried changing the line |
I'm sorry, I think I've gone about as far as I can with this problem. The fact that your Column D overflows the cell while mine doesn't (on both a Windows and a Linux system) is disappointing. I cannot match behavior, especially when it seems so capricious as this, in the absence of a spec. If you feel my PR is useful as-is, I can proceed with it; if not, I will scrap it. And, of course, even if I do scrap it, please feel free to create a PR of your own based on it that meets your needs. |
Yes, it seems to depend on more factors than I initially thought and I don't know how to solve it for everyone. |
Letting the new property be numeric rather than boolean is an interesting suggestion. I've changed my PR to do that. Can you test with it and see if comes close to meeting your needs. |
is going great 😉 |
Thanks for the feedback. I will take my PR out of draft status and move it forward in the next few days. |
* Preserve Transparency in Memory Drawing Fix #3626. User felt that Exact setting of column width should not add padding. In order to avoid making this a breaking change, I am adding a new boolean property `usePaddingForExact` with setter and getter to Shared/Font; default is false (current behavior). * Change Parameter Instead of bool, make it null|float|int, allowing user to set whatever is deemed appropriate.
This is:
What is the expected behavior?
The size of the columns is adjusted exactly to the text as in Excel in the columns B, C, and D.
What is the current behavior?
Despite setting the exact calculation method and the setAutoSize to true, there is still a lot of margin on the sides.
What are the steps to reproduce?
You can use the attached code to check it
Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:
If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Which versions of PhpSpreadsheet and PHP are affected?
PHP Version 7.4.33
PhpSpreadsheet 1.29.0
The text was updated successfully, but these errors were encountered: