-
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
[confusing] getStyle sets current selected fields #335
Comments
Your example would be better expressed as: <?php
require __DIR__ . '/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Fill;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$first = $sheet->getStyle('A1');
$second = $sheet->getStyle('A2');
$first->getFill()->setFillType(Fill::FILL_SOLID);
var_dump([
$sheet->getStyle('A1')->getFill()->getFillType(),
$sheet->getStyle('A2')->getFill()->getFillType(),
]); Expected output would be:
But actual output is:
So I agree it can be confusing. It means that you should use |
What do you guys prefer: Storing the selected fields in de returned object? |
I think keeping the same API and "only" changing the behavior would be the best, because it avoids breaking change and the API seems intuitive enough, except for the case described here. But that probably won't be a simple task. I'll let you have a better look at the code and we might talk more about it if/when you have an idea on how to do things |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
A method to avoid this issue was merged 2 weeks ago by PR #4073. |
As I only found out when looking at the source code, this doesn't work as expected:
The reason is that getStyle set the selected range. So when we do the second getStyle it overrides the first call. This is very confusion, especially since the name is getStyle
Proposal
It would be nice if the returned object holds the affected cells.
If that is too complicated, maybe just rename getStyle, so that it is clear it sets the selected cells.
Which versions of PhpSpreadsheet and PHP are affected?
1.0.0
The text was updated successfully, but these errors were encountered: