Exporting To Excel - Almost There

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Exporting To Excel - Almost There

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

If the user is downloading the file, then you cant
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Yep, totally not possibel.

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