populate a crosstab excel template

Topics: Developer Forum, User Forum
May 28, 2013 at 9:14 PM
I tried this for a week, and couldn find a way to do it. I need a report with the dates at the top, like this:
            01-may-2013        02-may-2013       03-may-2013 etc...
name
address
age
etc
etc
etc

all data (date, name, address,...) are on the same record, as seen above, I need to use the date field as column header.

We can see it as instead of listing the data horizontally, I need to do it vertically.
all data comes from a single table, anyone achieved this before?
May 29, 2013 at 9:59 AM
A bit vague... You can write where you want in the spreadsheet (within the limits inherent to the format). Accordingly, nothing prevents to write after your data in the first column, incrementing the line, and your date on the first line by incrementing column...
May 30, 2013 at 11:39 PM
Hi, lets say that I need the data to be displayed vertically, each new record on a new column (vertically); instead of the "normal" method of a new record per row (horizontally).
May 31, 2013 at 4:43 PM
Edited May 31, 2013 at 4:46 PM
$Col='A'; FirstLine=1;
while($ArrayData=getNextRow()){
    $Line=$FirstLine;
    $F->setCellValue($Col.$Line++, $ArrayData['date']);
    $F->setCellValue($Col.$Line++, $ArrayData['name']);
    $F->setCellValue($Col.$Line++, $ArrayData['address']);
    //others data
    $Col=PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($Col));
}
Replace getNextRows() with your function who return a array for a row or false (like mysqli_fetch_assoc()). $F is the sheet object (something like : $F=$objPHPExcel->getActiveSheet()).

The increment of $Col is 'hidden' : columnIndexFromString is in base 1 (A=1) and stringFromColumnIndex is in base 0 (A=0). Using the two methods this way, you have A ->1->B.