Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: How to include field names with mysql data

$
0
0

I would like to include the mySQL field names as line 1 in the generated xlsx. I have tried some things but have not had any luck. If anyone is willing to offer some advise on the subject I would be very appreciative. Here is my code:

 

$query = "SELECT * FROM evolve2012 WHERE cast(Date as DATE) BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() AND Blah Blah Blah";

if ($result = mysql_query($query) or die(mysql_error())) {
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setTitle('Data');   
}
$rowNumber = 1;
while ($row = mysql_fetch_assoc($result)) {       
$col = 'A'; // start at column A       
foreach($row as $cell) {         
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell);         
$col++;       
}       
$rowNumber++;

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="evolve2012-last7days.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;


Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>