Jump to content

Export query to excel with button


Zergman

Recommended Posts

So I was asked for there to be a button on a page that when clicked, will export the recordset to excel.

 

I can't seem to get this going but this is what I have found so far.

 

1) Using something like this to load the page right into excel

<?php  
header('Content-Type: application/vnd.ms-excel'); //IE and Opera  
header('Content-Type: application/x-msexcel'); // Other browsers  
header('Expires: 0');  
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');  
?>

 

2) Followed this tutorial http://wellknownmeats.com/export-html-data-to-ms-excel-a-phpjavascript-solution/ but can't get it to work either.

 

I don't mind using the header() option but I can't get it to work properly.  Don't know how to use it in my page.  I keep moving it around, but it just generates errors or does nothing at all.

 

Any help would be greatly appreciated

Link to comment
https://forums.phpfreaks.com/topic/126825-export-query-to-excel-with-button/
Share on other sites

Can i assume you didnt read the forum post here at the top about header errors?

http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

http://www.phpfreaks.com/forums/index.php/board,1.0.html (try looking)

 

Please do

But you cannot send a header if there is any HTML outputted before it, or you can cheat and put ob_start(); at the top of the page

I put this at the top of my page but it does nothing.  Page just loads normally but no errors.

 

<?php
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=NAME_OF_FILE.xls ");
?>

 

Sorry if im frustrating you, this stuff just doesn't make sense to me today

 

try

<?php

header("Content-Type: application/vnd.ms-excel");

header("Expires: 0");//and this maybe, just guessing, but do trial and error

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");//and this

header("Content-Type: application/force-download");// remove this

header("Content-Type: application/octet-stream"); // try removing this

header("Content-Type: application/download"); // you had 2 ; and remove this

header("Content-Disposition: attachment;filename=NAME_OF_FILE.xls ");

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.