1

I have an associative array, I need to display the items in Excel sheet. May I know how I can do the for loop in PHPSpreadsheet ?

$spreadsheet->getActiveSheet()
->fromArray(
    $arrayData,  // The data to set
    NULL,        // Array values with this value will not be set
    'A2',        // Top left coordinate of the worksheet range where
    'A1'         //    we want to set these values (default is A1)
);

Actually the above code is working fine. But I need to give some styles or colors to some item. As I display like above I don't know which section I need to change the style. If it is in for loop then it would be better.

mob_web_dev
  • 2,342
  • 1
  • 20
  • 42
  • Please advise what you have tried so far. – gclark18 Jan 28 '21 at 11:48
  • Does this answer your question? [Write data from array to sheet using phpspreadsheet library](https://stackoverflow.com/questions/48681839/write-data-from-array-to-sheet-using-phpspreadsheet-library) – El_Vanja Jan 28 '21 at 11:51
  • If you know the starting coordinates, then you can calculate which cell you need to modify. – El_Vanja Jan 28 '21 at 12:07
  • But you know every time the array length will be different. That's why I'm looking for for loop – mob_web_dev Jan 28 '21 at 12:11
  • Yes, but you know the length of the array, so you can loop through the correct number of rows, right? – gclark18 Jan 28 '21 at 12:29

0 Answers0