I want to add some style on a column using Laravel Excel. I know this column is the (let's say) 42nd, but I don't know the Excel code (like AA
, BC
, etc.).
I know I can build a function (based on this answer) to convert the column number to a letter, but I not sure it's the right way.
Is there a built-in way to convert a column number to an Excel column with Laravel Excel?
There is a method in PHPExcel
and i guess Laravel Excel uses that library.
You can do like this:
\PHPExcel_Cell::stringFromColumnIndex(1);
This will return, B
Since version 3.1 of Laravel Excel is based off of the newest PHP Excel which uses the latest PhpSpreadsheet classes, the helper functions to manipulate coordinates have been moved to a new dedicated class. Search for "Dedicated class to manipulate coordinates" on this page.
Therefore, you can do this moving forward:
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
...
Coordinate::stringFromColumnIndex(1);