Transform Vertical into Horizontal Output of Datas

Topics: Developer Forum, User Forum
Jul 24, 2012 at 7:33 PM
Edited Jul 24, 2012 at 7:34 PM

Hi Folks

i have a problem with an Output into an Excelfile from my MySQL Database and i hope anybody can help.

I have an ordinary:

 

Select name from person;

 

and i get an result like:

 

name
----------
USER 1
USER 2
USER 3
USER 4

 

How i can transform this resultset in a Horizontal line in PHPExcel like:

 

    B  |   C    |    D   |    E     
-----------------------------------------
USER 1 | User 2 | User 3 | User 4

 


It works good in PHP/HTML because there i work with the table <td> Tag.

like:

 

$qry = "Select name from person;" 

$res = mysql_query ($qry) or die("Error.");
$myRows1 = mysql_num_rows($res);
echo "<table><tr>";
while($row1 = mysql_fetch_row($res))
{
echo
"<td id='mygua1' align='center' >".$row1[0]."</td>";
} echo "</tr></table>";

How it is possible to transform this to the PHPEcel Writer?

THX in advance

Achillix

 

Coordinator
Jul 25, 2012 at 6:44 AM

$row=1; 
$column = 'A';
while($row1 = mysql_fetch_row($res)) 
{ 
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue( $column . $row , $row1[0] ); 
    $column++;
}

Jul 25, 2012 at 8:50 AM

Hi Mark,

Thank very much, it works great!!!