You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting column dimension setAutoSize(true) should set approximate column width.
What is the current behavior?
If a column cell has colors in numberFormat, the calculated cell value includes color pattern, hence the cell width is treated bigger.
See Worksheet::calculateColumnWidths()
You can see the differences of automatic column width with/without setFormatCode() line.
Worksheet::calculateColumnWidths() tries to get the cell value and next use its length to calculate the width.
The cell value is 170, displayed value is +170, but this code detects $cellValue as [Color 1170]+170:
// Calculated value
// To formatted string
$cellValue = NumberFormat::toFormattedString(
$cell->getCalculatedValue(),
$this->getParent()->getCellXfByIndex($cell->getXfIndex())
->getNumberFormat()->getFormatCode()
);
What features do you think are causing the issue
Calculations
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
XLS, XLSX
Which versions of PhpSpreadsheet and PHP are affected?
All versions.
The text was updated successfully, but these errors were encountered:
As you've noted, this isn't about using colours generally, but more specifically using a colour referenced by index [Color 10]. If you make your value negative (-170), then the colour [red] will be applied, and this will calculate the correct width.
This is because the built-in formatter doesn't recognise colours by index, only by name; so the problem lies specifically with the style formatter.
This is:
What is the expected behavior?
Setting column dimension
setAutoSize(true)
should set approximate column width.What is the current behavior?
If a column cell has colors in numberFormat, the calculated cell value includes color pattern, hence the cell width is treated bigger.
See
Worksheet::calculateColumnWidths()
What are the steps to reproduce?
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:
You can see the differences of automatic column width with/without
setFormatCode()
line.Worksheet::calculateColumnWidths()
tries to get the cell value and next use its length to calculate the width.The cell value is
170
, displayed value is+170
, but this code detects$cellValue
as[Color 1170]+170
:What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
XLS, XLSX
Which versions of PhpSpreadsheet and PHP are affected?
All versions.
The text was updated successfully, but these errors were encountered: