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
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

Link to comment
Share on other sites

I did read it but it hasn't sunk in yet.

 

I think I just don't understand where to put the header() code in my page.

 

Correct me if im wrong

 

<php code with quieries and stuff>

<form>

<header()>

...rest of page.

 

ugh, seems so simple lol

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 ");

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.