I'm new to PHPExcel and somehow I got the same data duplicated in the Excel spreadsheet using the following code:
$roster_sql = "SELECT * FROM EMPLOYEE";
$roster_result = mysql_query($roster_sql) or die(mysql_error());
//Populate 2D Array
$kcount = 0;
while($sheet_array = mysql_fetch_array($roster_result))
{
$rowID = 1;
foreach($sheet as $rowArray)
{
$columnID = 'A';
foreach($rowArray as $columnValue)
{
$rowID++;
}
The generated spreadsheet has each cell value duplicated in the column. Did I populate the array incorrectly or is there something wrong when I write out the array?
Further, how do I write the header row in the same spreadsheet without hard coding the column names from the SQL?
Thanks for your help.
$roster_sql = "SELECT * FROM EMPLOYEE";
$roster_result = mysql_query($roster_sql) or die(mysql_error());
//Populate 2D Array
$kcount = 0;
while($sheet_array = mysql_fetch_array($roster_result))
{
$sheet[$kcount] = $sheet_array;
$kcount++ ;
}$rowID = 1;
foreach($sheet as $rowArray)
{
$columnID = 'A';
foreach($rowArray as $columnValue)
{
$objPHPExcel->getActiveSheet()->setCellValue($columnID.$rowID, $columnValue);
$columnID++;
}$rowID++;
}
The generated spreadsheet has each cell value duplicated in the column. Did I populate the array incorrectly or is there something wrong when I write out the array?
Further, how do I write the header row in the same spreadsheet without hard coding the column names from the SQL?
Thanks for your help.