Page 1 of 1

Export Data to a excel file in the same page

Posted: Tue Aug 23, 2011 1:47 am
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...........

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

Posted: Fri Aug 26, 2011 9:47 am
by Jade
You'll need to use ajax to open the file and allow the download on the same page.