Reputation:
Is it possible to write into an excelsheet from A1 to Ax (vertically) with the fromArray function?
$objPHPExcel->getActiveSheet()->fromArray($array, NULL, 'A1');
What this line above does, is write from A1 to X1 (horizontal).
But is there anyway so that the output will be something like this:
$array[0]->A1
$array[1]->A2
$array[2]->A3
$array[x]->A(x+1)
Upvotes: 1
Views: 4986
Reputation: 212412
fromArray()
works with a 2-d array, of rows then columns. If you pass a 1-d array as an argument, then it will be converted to a 2-d array but as a series of columns for a single row.
You really need to pass a 2-d array instead, so that it is a series of rows instead.
$objPHPExcel->getActiveSheet()
->fromArray(array_map(function($value) { return [$value]; }, $array), NULL, 'A1');
Upvotes: 3