|
| |||||||||
| Tags: data, excel, export, php |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| php export to excel
How to php export to excel ? i want to export the data in table to the excel file through php . Please reply if you know how to do this. Thanks for any help. |
|
#2
| ||||
| ||||
| Re: php export to excel
The below php code can help you : Code: <?php
// DB Connection here
$select = "SELECT * FROM table_name";
$export = mysql_query($select) or die("Sql error : " . mysql_error());
$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) || trim($value) == "")
{
$value = "\t";
}
else
{
$value = str_replace('"' , '""' , $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line). "\n";
}
$data = str_replace("\r" , "" , $data);
if(trim($data) == "")
{
$data = "\n(0)Records Found!\n";
}
header("Content-type: application/msexcel");
header("Content-Disposition: attachment; filename=your_desired_name.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?> |
|
#3
| ||||
| ||||
| Re: php export to excel
Simplest way to generate an excel report. Code: <?php
$filename ="testreport.xls";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;
?> |
|
#4
| ||||
| ||||
| Re: php export to excel
I have successfully generated this xml with PHP and then opening it up using ms excel. It's nothing but just using a template to generate "XML Spreadsheet" data instead of HTML.
__________________ Grand Theft Auto 4 PC Video Game |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "php export to excel" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to export ical to excel | Xmen | Windows Software | 5 | 02-09-2010 08:41 AM |
| data export to excel | Irene | Microsoft Project | 1 | 11-12-2009 09:27 PM |
| Export OLE object to Excel? | Kelsey | Windows Software | 3 | 31-03-2009 10:29 PM |
| How can i export datatable to excel | Leena | Software Development | 3 | 30-01-2009 11:45 PM |
| Export to Excel | BW | Microsoft Project | 7 | 11-12-2008 12:44 AM |