Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Table to Excel File

images php coding issues or problems here.

Moderators: macek, egami, gesf

Table to Excel File

Postby rddcse » Fri Jun 11, 2010 12:34 pm

Hi I have designed a website containing a table fetching data from table.
I want to export this table as an ms excel i.e. .xls file.

Please reply with a sample code.

Thanks in advance. :help: :help: :help:
New php-forum User
New php-forum User
Posts: 8
Joined: Fri Jun 11, 2010 12:25 pm

Re: Table to Excel File

Postby theamol » Tue Jul 20, 2010 3:23 am

You should use pear spread sheet
download pear spread sheet and use the below code

Code: Select all
$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";

require_once 'Spreadsheet/Excel/Writer.php';

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

$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";


$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 hope this will solve your problem
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Jul 20, 2010 3:07 am

Re: Table to Excel File

Postby shridhar » Tue Aug 03, 2010 4:41 am

There are lots of libraries available in php for export to excel.
Also, while echoing set the content type in header() function as application/ms-excel.

Shridhar Govindaiah
Samartha InfoSolutions Pvt Ltd.
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Aug 03, 2010 2:07 am
Location: Bangalore

Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.