Page 1 of 1

Exporting To Excel - Almost There

Posted: Fri Apr 27, 2007 4:58 am
by NotOnUrNelly
Hi All,

I have copied the export mysql to excel tutorial from this website and it works fine.

I am trying to ammend the program so that the open,save or cancel box does not popup and the file is just saved to a specific location with a certain name.

ie

C:\temp\export.xls

The reason I need the file to be specific is becuase I want to run macros on the data to create charts and tables etc. I am then dragging the data in the named spreadsheet into a sheet that contains all of the macros. Therefore it is essential that the file is saved in the exact location and not named by the user which could lead to errors.

Here is the code for the export

Code: Select all

<?php
define (db_host,"mysql.xcalibre.co.uk");
define (db_user,"*****");
define (db_pass,"*****");
define (db_link,mysql_connect(db_host,db_user,db_pass));
define (db_name,"bridgeit");
mysql_select_db(db_name);



$select = "select * from tblResultsDesc";
$export= mysql_query($select);
$fields = @mysql_num_fields($export);

for ($i = 0;$i<$fields;$i++){
$header .= mysql_field_name($export,$i) . "\t";
}
while ($row = @mysql_fetch_row($export)){
$line = '';
foreach($row as $value){
if ((!isset($value))or($value=="")){
$value = "t";
}
else
{
$value = str_replace('"','""',$value);
//echo $value;
$value = '"' . $value . '"' . "\t";
}
$line .=$value;
}
$data .=trim($line)."\n";
//echo $data;
}
$data = str_replace("\r","",$data);


if ($data ==""){
$data = "n(0) Records Found!n";
}

header("Content-Type: application/vnd.ms-excel");
header ("Content-Disposition: attachment;fielname=extraction.xls");
header("pragma:no-cache");
header("Expires:0");
print "$header$data";
ob_end_flush();
?>

Many Thanks in Advance
Jamie

Posted: Fri Apr 27, 2007 5:30 am
by JayBird
If the user is downloading the file, then you cant

Posted: Fri Apr 27, 2007 5:33 am
by NotOnUrNelly
Jaybird,

what I really want is for the user to click a button and it palces the excel file on the C drive in a folder. It must be the same palce everytime.

The user does not really have to know that they are downloaidng the file. Just as long as when the user click the button the file is placed.

I just really want to lose the pop up box that asks for a file location.

Thanks for your help
Jamie

Posted: Fri Apr 27, 2007 5:53 am
by timvw
NotOnUrNelly wrote: what I really want is for the user to click a button and it palces the excel file on the C drive in a folder. It must be the same palce everytime.
Luckily enough this is not possible... Imagine that a person with other intentions uses this technique to install britneyspears.exe on your drive...

Posted: Fri Apr 27, 2007 6:29 am
by JayBird
Yep, totally not possibel.

P.S. ive removed your MYSQL username and password from your script