How to php export to excel

 
0
 

How to php export to excel

Featured Replies in this Discussion

 
0
 
<?php
$filename ="excelreport.xls";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;
 ?>

This is the simplest way to generate an excel report.

 
0
 

hi, i am janardhan..
i want some more coding details about export to excell sheet.. suppose i am retriving data from database and storing the values in a table. i want to export in an excell sheet with proper header ..how can i develop this.?

 
0
 

Replace testdata in the above example with the database values.

 
0
 

Can I change the color of contents ?
e.g testdata1 ---> blue
testdata2 ---> red
etc ...

Thanks!

 
0
 
<?php
$filename ="excelreport.xls";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;
 ?>

This is the simplest way to generate an excel report.

Hi,
Let me confess, I am ZERO in php.
I purchased one cd which has php files embedded with html page then scrolling pages in php formate withen windows of html .
Main data in in php file .
How to get this data in office document formate ( either MS Word or MS Excel)? Can some one help me in doing so....I am fed up.

 
0
 

Code is working well in localhost. When I Upload it, it is not exporting to excel,but printing it to a page.

 
1
 
$result=mysql_query("select * from tbl_name");
    function xlsBOF()
    {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
    return;
    }
    function xlsEOF()
    {
    echo pack("ss", 0x0A, 0x00);
    return;
    }
    function xlsWriteNumber($Row, $Col, $Value)
    {
    echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
    echo pack("d", $Value);
    return;
    }
    function xlsWriteLabel($Row, $Col, $Value )
    {
    $L = strlen($Value);
    echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
    echo $Value;
    return;
    }
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");;
    header("Content-Disposition: attachment;filename=list.xls");
    header("Content-Transfer-Encoding: binary ");
    xlsBOF();
     
    xlsWriteLabel(0,0,"Heading1");
    xlsWriteLabel(0,1,"Heading2");
    xlsWriteLabel(0,2,"Heading3");
    $xlsRow = 1;
    while($row=mysql_fetch_array($result))
    {
    xlsWriteNumber($xlsRow,0,$row['field1']);
    xlsWriteLabel($xlsRow,1,$row['field2']);
    xlsWriteLabel($xlsRow,2,$row['field3']);
    $xlsRow++;
    }
    xlsEOF();
Comments
Good
 
0
 

Hey Karthik.R,
Thanks for your Reply.I resolved my Error. Actually it was headers problem. I turned off all the errors and warnings. Now I have another problem. I am exporting time to ods file. After exporting in ods(openoffice) file, the Time (e.g 08:00) is showing as 08:00:00 AM. I want to show it as it is in my db. Do you know have any idea about that. Kindly Post here.

 
0
 

Sorry i'm not clear with your question. What you mean by ods file?

 
0
 
<?php if (!$HTTP_GET_VARS['submit']) { ?>

<?php
echo "Export and Save Customer Data onto your Local Machine";
echo '<form action="'. $phpself.'">';
echo '<input type="submit" value="Export" name="submit"></form>';
?>

<?php
}
else
{
$contents="Board Category,Questions,Answers\n";
$user_query = mysql_query('select
f.faqdesk_id
, c.categories_id
, f.faqdesk_question
, c.categories_name
, f.faqdesk_answer_short
from faqdesk_description as f
join faqdesk_to_categories as f2c
on f.faqdesk_id = f2c.faqdesk_id
join faqdesk_categories_description as c
on f2c.categories_id = c.categories_id');
while($row = mysql_fetch_array($user_query))
{
$contents.=$row[categories_name].",";
$contents.=$row[faqdesk_question].",";
$answer = str_replace(',', '\,', $row[faqdesk_answer_short]); // escape internalt commas
$contents.=$answer."\n";
}
$contents = strip_tags($contents); // remove html and php tags etc.
Header("Content-Disposition: attachment; filename=export.csv");
print $contents;

?>
 
0
 

Thanks a lot for yor time to write this code down.

Have a nice day

 
0
 

@Karthik_pranas great! that works like a charm! thanks!!

 
0
 

can anyone tell how to print excel sheet values in php?

 
0
 

<?php
$filename ="excelreport.xls";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;
?>

 
0
 

You can try Exls (XMlSpreadSheet) in exls.ru (has demo and examples of templates of xls files)

 
0
 

can i make some excel file without window prompt

 
0
 

can i export some data from php web page to excel

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: