0

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?

rap-2-h
  • 26,857
  • 31
  • 150
  • 246
  • You want to export full table or some columns ? I have used laravel excel but i did't find any such inbuilt function. but I have develop my own function for that. – Raunak Gupta Oct 06 '16 at 13:24

2 Answers2

4

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);
Patrick.SE
  • 4,207
  • 5
  • 31
  • 44
1

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

Can Vural
  • 1,956
  • 1
  • 24
  • 39