php - PHPEXCEL Get mysql column name in Single Row -
php - PHPEXCEL Get mysql column name in Single Row -
i working on application, user upload file (any format) , application process per utilize , download it.
i want add together column name mysql in single row coming follows:
name mobile city mick 9xxxxxxxx ahmedabad
my code follows:
$result=mysql_query("select * test_excel") or die(mysql_error()); $objphpexcel = new phpexcel(); $objphpexcel->setactivesheetindex(0); $row=1; $q = mysql_query("show columns test_excel"); if (mysql_num_rows($q) > 0) { while ($row_q = mysql_fetch_assoc($q)) { $col='a'; $objphpexcel->getactivesheet()->setcellvalue($col.$row, $row_q['field']); $col++; } $row++; } while($row_data1 = mysql_fetch_assoc($result)){ $col=0; foreach($row_data1 $key=>$value){ $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $value); $col++; } $row++; } $objwriter = new phpexcel_writer_excel2007($objphpexcel); header('content-type: application/vnd.ms-excel'); header('content-disposition: attachment; filename="file.xls"'); $objwriter->save('php://output');
pls right me wrong.
pb
you resetting column in each loop. alter this:
if (mysql_num_rows($q) > 0) { $col='a'; while ($row_q = mysql_fetch_assoc($q)) { $objphpexcel->getactivesheet()->setcellvalue($col.$row, $row_q['field']); $col++; } $row++; }
also should not utilize mysql functions outdated. mysqli or pdo instead.
php phpexcel
Comments
Post a Comment