shadedecho
Programmer
I know this is like the most simple type of thing, but I can't seem to make this work.
I want to have a .php file which based on a parameter that is passed to it, it generates a particular set of data in CSV format, and I want to signal for the viewer of this page to have it automatically launch and be viewed in Excel. (the user of this page will always be on a windows machine with microsoft excel 97 or 2000).
so what I have is this:
blah.php:
then in the browser, its simply called by:
blah.php?param=val1
So, when I do this with just typing that into a new browser window, I get my data printed out fine, but it doesn't launch Excel to open the data, just prints it in text.
But, if i have a javascript launch a new popup window (which is how my application will do it) with that blah.php?param=val1 as the source file, i get an error that says "Excel could not open the file and then the next error box after it talks about "...could be one of several reasons" and it mentions things like the file/path not existing, or the file being in use, or that the name of the workbook that i'm trying to save is the same as a read-only one.
None of these errors make any sense to me. I think I must not be sending the correct/enough headers to tell Excel how to launch. Can someone please tell me what I need to do?
I want to have a .php file which based on a parameter that is passed to it, it generates a particular set of data in CSV format, and I want to signal for the viewer of this page to have it automatically launch and be viewed in Excel. (the user of this page will always be on a windows machine with microsoft excel 97 or 2000).
so what I have is this:
blah.php:
Code:
<?php
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: inline; filename=blah.csv");
echo "field1,field2,field3";
echo $param.",val2,val3";
exit;
?>
then in the browser, its simply called by:
blah.php?param=val1
So, when I do this with just typing that into a new browser window, I get my data printed out fine, but it doesn't launch Excel to open the data, just prints it in text.
But, if i have a javascript launch a new popup window (which is how my application will do it) with that blah.php?param=val1 as the source file, i get an error that says "Excel could not open the file and then the next error box after it talks about "...could be one of several reasons" and it mentions things like the file/path not existing, or the file being in use, or that the name of the workbook that i'm trying to save is the same as a read-only one.
None of these errors make any sense to me. I think I must not be sending the correct/enough headers to tell Excel how to launch. Can someone please tell me what I need to do?