1753894 Members
7685 Online
108809 Solutions
New Discussion

php script

 
Sasirekha
Occasional Contributor

php script

Hi

I generated a excel file which contains the data fetched form mysql database.I used the following to do it

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=spreadsheet.xls");
header("Pragma: no-cache");
header("Expires: 0″);
print “$headern$data";

using this I could generate an excel file with only one spreadsheet having the file name.
I NEED TO GENERATE 2 SPREADSHEETS in a single excel sheet and each sheet should contain a table content fetched from the db in the same format as in db.

The another way I tried is like below

require_once('C:\apachefriends\xampp\php\pear\Spreadsheet\Excel\Writer.php'); //specify path
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();
// sending HTTP headers
$sel_USchema = filename;
if($sel_USchema!= 'None')
{
$workbook->send($sel_USchema.'.xls'); //specify path
// Creating a worksheet
$worksheet =& $workbook->addWorksheet('Products');
$worksheet =& $workbook->addWorksheet('Products_details');
$workbook->close();
}
else
{
alert("Please select any UserSchema Name");
}
?>
with the above code I was could generate 2 spread sheets in single excel file but struck up while trying to write the data in the 2 sheets..

Please help me out..

Thanks
2 REPLIES 2
Frijo Franco
Advisor

Re: php script

Try Adding One and add data to it and add the second one. Else use the select() oject to select the sheet and then add. or you can use seperate variables for each sheet and then you can add it.

A Sibple sample is given below.

require_once 'C:\php\Excel\Writer.php';

// We give the path to our file here
$workbook = new Spreadsheet_Excel_Writer('C:\php\Excel\test.xls');

$worksheet1 =& $workbook->addWorksheet('Products');
$worksheet1->write(0, 0, 'Name');
$worksheet1->write(0, 1, 'Age');
$worksheet1->write(1, 0, 'John Smith');
$worksheet1->write(1, 1, 30);
$worksheet1->write(2, 0, 'Johann Schmidt');
$worksheet1->write(2, 1, 31);
$worksheet1->write(3, 0, 'Juan Herrera');
$worksheet1->write(3, 1, 32);
$worksheet1 =& $workbook->addWorksheet('Products');

$worksheet2 =& $workbook->addWorksheet('Products_details');
$worksheet2->write(0, 0, 'Name');
$worksheet2->write(0, 1, 'Age');
$worksheet2->write(1, 0, 'Frijo');
$worksheet2->write(1, 1, 30);
$worksheet2->write(2, 0, 'John Antony');
$worksheet2->write(2, 1, 31);
$worksheet2->write(3, 0, 'James Rad');
$worksheet2->write(3, 1, 32);
// We still need to explicitly close the workbook
$workbook->close();
?>

Peter Godron
Honored Contributor

Re: php script

Hi,
seems you have forgotten about your other thread covering the same topic:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1057181

Everytime you provide updates, your thread 'bounces' to the top of the forum tree, so no need to generate additional threads.