php - Using PHPExcel to export to xlsx -
i using phpexxcel export html table generated using mysql , this.
<?php $query = "select `firstname`,`lastname`,`branch`,`gender`,`mobileno`, `email` `student_details` branch in ('$branch') , `year`='$year' , tenthresult > '$tenth' , twelthresult > '$twelth' , (cgpa > '$cgpa' || cgpa = '$cgpa')"; $result = mysql_query($query); confirm_query($result); $objphpexcel = new phpexcel(); $objphpexcel->setactivesheetindex(0); $rowcount = 1; $objphpexcel->getactivesheet()->setcellvalue('a'.$rowcount,'firstname'); $objphpexcel->getactivesheet()->setcellvalue('b'.$rowcount,'lastname'); $objphpexcel->getactivesheet()->setcellvalue('c'.$rowcount,'branch'); $objphpexcel->getactivesheet()->setcellvalue('d'.$rowcount,'gender'); $objphpexcel->getactivesheet()->setcellvalue('e'.$rowcount,'mobileno'); $objphpexcel->getactivesheet()->setcellvalue('f'.$rowcount,'email'); while($row = mysql_fetch_array($result)){ $rowcount++; $objphpexcel->getactivesheet()->setcellvalue('a'.$rowcount, $row['0']); $objphpexcel->getactivesheet()->setcellvalue('b'.$rowcount, $row['1']); $objphpexcel->getactivesheet()->setcellvalue('c'.$rowcount, $row['2']); $objphpexcel->getactivesheet()->setcellvalue('d'.$rowcount, $row['3']); $objphpexcel->getactivesheet()->setcellvalue('e'.$rowcount, $row['4']); $objphpexcel->getactivesheet()->setcellvalue('f'.$rowcount, $row['5']); } $objwriter = new phpexcel_writer_excel2007($objphpexcel); $objwriter->save('some_excel_file.xlsx'); ?>
its working saves xlsx file in root folder without showing user signs being downloaded. code rund when click button.now, can make downloaded download mail attachment , showing user in front end being downloaded along location.
i tried using
header('content-type: application/vnd.ms-excel'); header('content-disposition: attachment;filename="01simple.xls"'); header('cache-control: max-age=0');
with this, getting wanted above xls file downloaded when opened shows message 'the file trying open 'filename' in different format specified extension.....etc.do want open now?
on opening contains either entire html page or blank... can me..?
spreadsheets 101
there many different spreadsheet file formats, each own different filename extensions, , can sent web browser using different mime types. these described in phpexcel documentation, , each has own different writer in phpexcel. you're mismatching 2 different formats
biff format
used microsoft excel between versions 95 , 2003 file
extension: xls
phpexcel writer: phpexcel_writer_excel5
mime type: application/vnd.ms-excel
officeopenxml format
used microsoft excel since version 2007
file extension: xlsx
phpexcel writer: phpexcel_writer_excel2007
mime type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
don't mix , match: if do, excel (and justifiably) complain. if want biff file, use phpexcel's biff writer (excel5), file extension of .xls, , mime type listed above biff format. if want officeopenxml file, use phpexcel's excel2007 writer, file extension of .xlsx, , mime type listed above officeopenxml.
edit
note examples provided phpexcel distribution include 01simple-download-xls.php , 01simple-download-xlsx.php demonstrate want
Comments
Post a Comment