exporting data into multiple sheets in excel

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
bugthefixer
Forum Contributor
Posts: 118
Joined: Mon Mar 22, 2004 2:35 am

exporting data into multiple sheets in excel

Post by bugthefixer »

I have searched for exporting data from mysql into excel but the code i have got puts the data only in one sheet is there
any way so that i can put data into multiple sheets like each table sould go in separate sheet .... Here's the code that i am using

Code: Select all

$con = mysql_connect("localhost" , "root" , "") or die ("Not Fouund" . mysql_error()); 
mysql_select_db("hic_data") or die ("Not Fouund" . mysql_error()); 
$select = "SELECT * FROM tbresponsera";                  
$export = mysql_query($select,$con); 
echo mysql_error($con); 
$fields = mysql_num_fields($export);  
$header = "" ; 
$data = ""; 
for ($i = 0; $i < $fields; $i++) {  
    $header .= mysql_field_name($export, $i) . ",";  
}  
while($row = mysql_fetch_row($export)) {  
    $line = '';  
    foreach($row as $value) {                                              
        if ((!isset($value)) OR ($value == "")) {  
            $value = "£";  
        } else {  
            $value = $value. "£";  
        }  
        $line .= $value;  
    }  
    $data .= trim($line)."new line";  
}  
$data = str_replace("r","",$data);  

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

$title_row = split(",", $header);

foreach($title_row as $title)
	$st_data = $st_data."$title \t";
	
$data_row = split("new line", $data);
foreach($data_row as $row)
{
	$st_data = $st_data."\n";
	$data_dis = split("£", $row);
	foreach($data_dis as $col)
		$st_data = $st_data."$col \t";
	
}

header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=extraction.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 

print "$st_data";
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Post by ody »

Check this out it should be what your looking for.
Post Reply