get columns name

Oct 18, 2011 at 3:52 PM
Edited Oct 18, 2011 at 3:57 PM

Hi,

Is it possible to get column name from array, with is index when i write excel ?

ex : $d = array( 'col 1'=> 'blabla 1', 'col 2'=>'blabla 2');

i use

 

$objPHPExcel = new PHPExcel();

$objPHPExcel->getActiveSheet()->fromArray($d, null, 'A1');

i want

col 1 | col 2 <----- header
------------------
blabla1 | blabla2


nowaday, i have this

blabla | blabla2

regards
Oct 18, 2011 at 3:54 PM

so instead of A1, you just want A?

 

$column = preg_replace('/\d+/', '', 'A1');

Oct 18, 2011 at 3:59 PM

No, i want key from array to display header column

Oct 18, 2011 at 4:01 PM
Edited Oct 18, 2011 at 4:03 PM

ah, spreadsheets don't have headers ;) Do you mean the values of the first row?

 

something like this?

$objPHPExcel->getActiveSheet()->fromArray(array_keys($d), null, 'A1');

Oct 18, 2011 at 4:03 PM
Edited Oct 18, 2011 at 4:09 PM

Yes, absolutely

 

Array
(
[0] => Array
  (
  [col1] => blabla1
  [col2] => blabla2