Export Data to a excel file in the same page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

Export Data to a excel file in the same page

Post by ishakya »

Hi, i need to export particular data to a excel file.
When user clicks on the export to link i need to display a pop up saying "Export to excel".I have some part of this.But the matter is excel creating page is showed in another tab.
$f is='453'

Code: Select all

<a href="../excel1/reorder.php?id='.$f.'">Export</a>';?>
and after that
page redirect to this:

Code: Select all

<html>
<head>
<script language="javascript">
function download()
{
    window.location='report.xls';
}
</script>
</head>
<body onLoad="download();">

<?php


require_once("excelwriter.class.php");
require_once('../library/myconn.php');

              $u=$_POST['rquery'];
              $fname=$_POST['rfields'];
              


$excel=new ExcelWriter("report.xls");
if($excel==false)    
echo $excel->error;

$myArr=(explode(",",$fname));

$excel->writeLine($myArr);


$resultu=mysql_query($u);
while ($rowu = mysql_fetch_array($resultu)) {
    
      for($i=0;$i<count($rowu);$i++){
      
    $myArr[$i]=$rowu[$i];
    
       }    
       $excel->writeLine($myArr);    
}
// header("refresh: 2; ../import/search_result.php");
//exit;
    
?>

</body>
</html>
The thing is i need to stay on the same page when user tries to export data to a excel...
I hope everyone got the idea...
Thanks in advance...
Waiting to see some help thanks...........
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Export Data to a excel file in the same page

Post by Jade »

You'll need to use ajax to open the file and allow the download on the same page.
Post Reply