From the course: PHP: Exporting Data to Files

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Populating an Excel spreadsheet with data

Populating an Excel spreadsheet with data - PHP Tutorial

From the course: PHP: Exporting Data to Files

Start my 1-month free trial

Populating an Excel spreadsheet with data

Before adding the data, let's take another quick look at the finished spreadsheet. PHP xl needs to know which cell to put each item into. Across the top, each column is referred to by a letter beginning with A. Our database results has seven columns. So the final one is G. Each row has a number beginning at one. So the column headings go in cells A1 to G1. The final column G, contains a lot of text. So we'll need to make that wider than the other columns, but we can set the other columns to autosize. So they'll expand or contract depending on the size of the data that's in them. Each cell needs to be populated individually using the column letter and row number as a reference. So now we know what we've got to do, let's get back to the editing program and get to work. The code needs to go at the bottom of the tri block after the code that we've already created. I'm going to add a few lines after line 28, and then the first thing is to get the first row from the database result. So…

Contents