1

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)

1 Answer 1

3

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.