PhpSpreadsheet
PhpSpreadsheet copied to clipboard
setCellValueByColumnAndRow deprecated??
Hello fellows, I am trying to use the library on one of my projects and when i tried to use setCellValueByColumnAndRow it says the following:
Fatal error: Uncaught Error: Call to undefined method PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::setCellValueByColumnAndRow() in xxxxx
Can anyone help ??I tried to search the issues with the method name but no luck there.
It was deprecated long ago, and removed with PhpSpreadsheet 2.0.0. You can replace:
setCellValueByColumnAndRow($column, $row, $value);
with
setCellValue([$column, $row], $value);
It would've been nice if the removal notice was included in the 2.0.0 release notes instead of a subtle reference to a huge commit of deprecated things: https://github.com/PHPOffice/PhpSpreadsheet/commit/816b91d0b4a0c7285a9e3fc88c58f7730d922044 I ran into this to trying to update an existing project. Hopefully there aren't any other breaking changes that aren't in the release notes.
The deprecations are all listed in CHANGELOG.md when they first happen. In the case of this change, that would be the release notes for 1.23.0 from April 2022. You can search for "deprecated" in that file to make sure you aren't adversely affected by something else. I agree that this could have been made clearer in the 2.0.0 release notes; we will try to bear this in mind for future releases.
Thanks. I found another deprecation (FORMAT_DATE_YYYYMMDD2) in a later 1.* release too, In case anybody runs into the same issues as me, here are the sed commands I used to save time:
grep -rF -l --exclude-dir=.git --include=*.php -- ByColumnAndRow | grep -vF vendor | xargs sed -i -r 's/(setCellValue)(Explicit)?ByColumnAndRow\(([^,]+,[^,]+)(,)/\1\2([\3]\4/g'
grep -rF -l --exclude-dir=.git --include=*.php -- ByColumnAndRow | grep -vF vendor | xargs sed -i -E 's/(getCell)ByColumnAndRow\(([^,]+,[^,)]+)/\1([\2]/g'
grep -rF -l --exclude-dir=.git --include=*.php -- ByColumnAndRow | grep -vF vendor | xargs sed -i -E 's/(getStyle)ByColumnAndRow\(([^)]+)/\1([\2]/g'
grep -rF -l --exclude-dir=.git --include=*.php -- ByColumnAndRow | grep -vF vendor | xargs sed -i -E 's/(mergeCells)ByColumnAndRow\(([^)]+)/\1([\2]/g'
grep -rF -l --exclude-dir=.git --include=*.php -- FORMAT_DATE_YYYYMMDD2 | grep -vF vendor | xargs replace FORMAT_DATE_YYYYMMDD2 FORMAT_DATE_YYYYMMDD --
I believe the release notes for 3.3.0 do a better job of explaining functions which were removed. Closing this issue.