Thanks for the code. --- Ankit Mathur <ankitmathur82@xxxxxxxxxxx> wrote: > Hi, > > I've been successfully using the following code to > export data displayed on a web-page in a excel file. > > I hope it turns out to be of help to anyone wanting > to export data from a webpage to EXCEL File. > > Ankit Mathur > > > Code in the page YOU WANT TO EXPORT > > $sql="SELECT AccountId,StartDateTime,DestinationNo > FROM custinfo WHERE AccountId=$acctid"; > > > <form id="form1" name="form1" method="POST" > action="dbxcel.php"> <input > name="sql" type="hidden" value="<?php echo $sql; ?>" > /> <input name="cdr" > type="hidden" value="1" /> <input > type="submit" name="submit" id="submit" > value="Export in Excel" /></form> > > DBXCEL.PHP > > <?phpheader("Content-Type: > application/vnd.ms-excel");header("Expires: > 0");header("Cache-Control: must-revalidate, > post-check=0, pre-check=0"); > > include("dbconn.php"); > > $getsql=$_POST['sql'];$sql=stripslashes($getsql);# > echo $sql; > $result=mssql_query($sql);$num=mssql_num_rows($result); > if($_POST['cdr']==1) {?><table border="1" > bordercolor="#105D90" width="100%"> <tr height="20"> > <td colspan="9" align="center" > bgcolor="#D3D3D3"><b>Account CDR</b></td> </tr> <tr > align="center"> <td bgcolor="#95CDE8" > width="5%">S.No</td> <td bgcolor="#95CDE8" > width="15%">AccountId</td> <td bgcolor="#95CDE8" > width="25%">Call Date</td> <td bgcolor="#95CDE8" > width="30%">Called Number</td> > </tr><?php$i=1;while($arr=mssql_fetch_array($result,MSSQL_ASSOC)){ > $value += $arr['Duration']; $value1 += > $arr['Cost'];?> <tr> <td > bgcolor="#EDF2F6"> <?php echo $i;?>.</td> <td > bgcolor="#EDF2F6"> <?php echo > $arr['AccountId'];?></td> <td > bgcolor="#EDF2F6"> <?php echo > $arr['StartDateTime'];?></td> <td > bgcolor="#EDF2F6"> <?php echo > $arr['DestinationNo'];?></td> </tr><?php $i++;}?> > <tr> <td bgcolor="#95CDE8" colspan="4"> </td> > </tr></table><?php } // If Loop Ends?> > > > To: php-objects@xxxxxxxxxxxxxxxxxxx: > finals27@xxxxxxxxxxxxx: Sun, 28 Oct 2007 10:31:07 > +0000Subject: Exporting data in mysql > to an excel sheet > > > > > I have developed a reporting page using php which > will display the number of records from a table to > the browser. This works fine, however i would like > to provide user an option where 1. they can view the > report in an excel sheet which can be opened or > saved with a dialog box and2. i would like the field > names to be added in the first row of the excel > sheet exactly how it happens while exporting a table > from Myphp admin interface.Please provide the code > for this. Any help will be greatly appreciated. > > > > > > > _________________________________________________________________ > Call friends with PC-to-PC calling -- FREE > http://get.live.com/messenger/overview > > [Non-text portions of this message have been > removed] > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com