-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Export only data cells/columns in toArray #4642
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
base: master
Are you sure you want to change the base?
Export only data cells/columns in toArray #4642
Conversation
I assume you can figure out the phpcs failure on your own. Let me know if you need assistance for that. The failing test is peculiar. The values on the spreadsheet are integers, but the test is comparing to floats. I don't see why your change should have affected anything, but the test is less than optimal anyhow. I would have no objection to your making the following changes: $data = $spreadsheet->getActiveSheet()->toArray(formatData: false);
$ref = [1, null, 3, null, 5, null, 7, null, 9, null];
for ($i = 0; $i < 10; ++$i) {
self::assertSame($ref, \array_slice($data[$i], 0, 10, true));
} That being said, there has been a lot of discussion in various issues about get... vs getHighest... I need to study those to make sure that the current code does not use getHighest for a reason |
4058c8c
to
eb33a0b
Compare
Fixed the formatting. For the test: the test failing was actually related to my change. But it is not about the float/int conversion - in fact, toArray() returns all cells as What happens there, is the rightmost column (containing '10') is not loaded because of the filter The other way to fix the test would be to use |
Worksheet::toArray now calls these methods: $maxCol = $this->getHighestDataColumn(); $maxRow = $this->getHighestDataRow(); instead of getHighestColumn and getHighestRow. This is to make sure that rows/columns that only have some formatting are not included. Otherwise the export would contain 16384 columns if e.g. column width setting is applied.
eb33a0b
to
13e24b2
Compare
I was thinking about this a bit more, and fixed the test in a different way. So the scope of this test is to see if read filters work. But given that the example XLSX file used in the test has cell formatting beyond data cells (the latter are the 10x10 matrix A1:J10), it was affected by the behavior of Thus the fix is to use |
Your work on this is exemplary. Unfortunately, as I mentioned was a possibility, I will not be able to merge this change in its present form. See #3982 (comment). The fact that your change broke an unrelated test confirms that it is indeed a breaking change. Although I cannot merge this change, the idea behind it is worthwhile. I imagine that most users would want your behavior rather than how PhpSpreadsheet handles the situation now. But a breaking change is a breaking change. It is not something we take lightly, especially since PhpSpreadsheet already provides a means to get the result you want: rangeToArray('A1:' . $sheet->getHighestDataColumn() . $sheet->getHighestDataRow); However, I would not be averse to adding an extra parameter to Thank you again for your work on this change. I am sorry that it has so far led to a disappointing outcome. |
This is:
Checklist:
Why this change is needed?
Worksheet::toArray now calls these methods:
instead of getHighestColumn and getHighestRow. This is to make sure that rows/columns that only have some formatting are not included. Otherwise the export would contain 16384 columns if e.g. column width setting is applied.