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
  • 30,204
  • 37
  • 167
  • 263
  • 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

5

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,444
  • 5
  • 34
  • 44
2

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
  • 2,222
  • 1
  • 28
  • 43