By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

php code "export table to excel"

P: 22
Hello Guys,....!
Can you help me how to export my table to excell using php code ..?
thanks alot
Feb 13 '07 #1
Share this Question
Share on Google+
2 Replies


P: 17
You should use pear spread sheet
download pear spread sheet and use the below code
[PHP]
<?php
/*
$Id: report_all.php,v 1.1 2004/08/30 16:03:40 chris Exp $
generate a spreadsheed from and addressbook in mysql database.
*/

include "dblib.php";
DBConnect();

require_once 'Spreadsheet/Excel/Writer.php';

$workbook = new Spreadsheet_Excel_Writer();
$format_bold =& $workbook->addFormat();
$format_bold->setBold();

$worksheet =& $workbook->addWorksheet();
$worksheet->write(0, 0, "name", $format_bold);
$worksheet->write(0, 1, "address", $format_bold);
$worksheet->write(0, 2, "phone", $format_bold);
$worksheet->write(0, 3, "email", $format_bold);
$worksheet->write(0, 4, "comments", $format_bold);

# start by opening a query string
$fullquery="select * from smslog";

$result=mysql_db_query($db_name,$fullquery);

$i=1;
while($row=mysql_fetch_assoc($result)){
$worksheet->write($i, 0, "$row[name]");
$worksheet->write($i, 1, "$row[address]");
$worksheet->write($i, 2, "$row[phone]");
$worksheet->write($i, 3, "$row[email]");
$worksheet->write($i, 4, "$row[comments]");
$i++;
}
$workbook->send('test.xls');
$workbook->close();
?>[/PHP]
I hope this will solve your problem
Feb 13 '07 #2

P: 22
thanks alot you're amazing.
regards
Feb 13 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.