-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Column fill not working #4285
Comments
This is an admittedly kludgey solution, and I will look into whether something better can be done. In the meantime, after setting the column style the way you want, pick a cell with the correct styling and: $xfIndex = $sheet->getCell('A5')->getXfIndex();
$sheet->getColumnDimension('A')->setXfIndex($xfIndex); |
Thank you for your answer. I found another workaround. $sheet->getStyle('A:A')->getFill()->applyFromArray([
'fillType' => 'solid',
'startColor' => ['argb' => 'FFFFFF00'],
]); |
Thank you for sharing that information. Your solution is much less kludgey than mine. I confess that I do not understand why applyFromArray works differently than applying the style directly, but I can confirm that it does. |
Fix PHPOffice#4285. Documentation change only - no changed code. It is not clear to me why using individual set options when styling an entire column works differently than applyFromArray, but the latter produces the expected result and the former doesn't. I will continue to research why. However, in the meantime, we can at least document that applyFromArray is preferred for this operation.
This is the second recent occasion where style for whole row or column is behaving unexpectedly (see issue PHPOffice#4285). For the earlier issue, a documentation update was made to show the preferred method of styling. Setting styles for row(s) or column(s) in that way will work just fine, however retrieving the style doesn't yield the expected result. Although that problem can be overcome with existing code, simpler methods are needed, and this PR adds methods getRowStyle and getColumnStyle to Worksheet. I will continue to investigate why this problem and the one from 4285 have unexpected results.
This is:
What is the expected behavior?
All cells in the column are colored.
What is the current behavior?
Blank cells are not colored.
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:
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 8.4.1
PhpSpreadsheet 3.6.0
The text was updated successfully, but these errors were encountered: