0

Newbie here, here's the question : Does PhpSpreadSheet have a function to generate an .xlsx file from a PHP array automatically?

I searched but could not find.

So far, I only found the setCellValue() function which (obviously) allows me to set the value of a cell. I would like to set the values of a lot of cells so I am going to use a for-loop to do that, unless there is already a function that does that.

If it does exist, I assume it should probably look like that :

$cell = [Number of the first excel cell you want to write (e.g : 'B2')]

$path = [Path of the file you want to write (e.g : 'php://output')]

$mysheet->arrayToXlsx($cell, $path)

I am going to use this quite a few times in the next days so please let me know if this function is already provided by PhpSpreadSheets !

GSD
  • 1,252
  • 1
  • 10
  • 12
AniMir
  • 150
  • 12
  • 1
    Why not write such code on your own? – Nico Haase Mar 06 '19 at 16:00
  • Of course I could and I probably will, however this function may have more features I would like to be aware of, that is if it exists. – AniMir Mar 06 '19 at 16:58
  • The spreadsheet object has a method called `fromArray()` that will fill a range of cells with data from an array. But there much to do in order to create a spreadsheet. Your best friend will probably be [the documentation](https://phpspreadsheet.readthedocs.io/en/latest/). The [source code](https://github.com/PHPOffice/PhpSpreadsheet) has a large number of excellent how-to examples. – DFriend Mar 06 '19 at 21:50

0 Answers0