0

I am generating an excel sheet using PhpSpreadSheet

However, the header is dynamic as it's information taken from database. How would I loop through each letter, for example from A until necessary (based on database info) to fill each cell with its name?

For example: enter image description here

As you can see, I got 4 cells filled with information which is taken from database. I didn't know that there will be 4 "tests". So how can I set the header like this, without knowing the actual length?

EDIT:

foreach($headings as $head) {
            $sheet->setCellValue('A1', $head);
        }

So $head represents a test. There can be 4, 8, 9, 5, 21 tests. In this code snippet it fills the A1 cell with tests. I just want to loop from A1 until necessary1 so I can feel the cells with tests. I don't know the necessary letter as there can be any number of tests up to 31

How can I loop from A1 to X1 (X can be any letter, even AB), not knowing the actual letter X?

Cristian25
  • 129
  • 1
  • 6
  • With a `foreach` loop? It's unclear what you've tried or what problem you're having precisely. Where are you stuck with this? Are you asking how to loop through a list of letters so you can reference cells by their alphabetical code? – ADyson Oct 27 '22 at 21:18
  • Does this answer your question? [Most efficient way to get next letter in the alphabet using PHP](https://stackoverflow.com/questions/2673360/most-efficient-way-to-get-next-letter-in-the-alphabet-using-php) - it'll even do the AA, AB thing when you get to Z! – ADyson Oct 27 '22 at 21:46

0 Answers0