Loading ...
Sorry, an error occurred while loading the content.

RE: [php-objects] Exporting data in mysql to an excel sheet

Expand Messages
  • khalid anwar
    after doing the implode stuffs with the result set. use header function like this header( Content-Disposition: attachment; filename=yourfilename.csv );
    Message 1 of 9 , Oct 31, 2007
    • 0 Attachment
      after doing the implode stuffs with the result set.

      use header function like this

      header("Content-Disposition: attachment; filename=yourfilename.csv");
      header("Content-Type: text/csv; charset=UTF-8");
      header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
      header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
      header( "Cache-Control: post-check=0, pre-check=0", false );
      header("Content-Length: ".strlen($cont));
      echo $cont;

      hope this will help you , cheers :)

      "Atkinson, Robert" <ratkinson@...> wrote: There's a class on phpclasses.org
      (http://www.phpclasses.org/browse/package/2037.html) that can be used to
      create Excel files.

      Rob.

      ________________________________

      From: php-objects@yahoogroups.com on behalf of Sudhakar
      Sent: Sun 10/28/2007 10:31 AM
      To: php-objects@yahoogroups.com
      Subject: [php-objects] 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 and
      2. 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.

      ***********************************************************************************
      Any opinions expressed in email are those of the individual and not necessarily those of the company. This email and any files transmitted with it are confidential and solely for the use of the intended recipient
      or entity to whom they are addressed. It may contain material protected by attorney-client privilege. If you are not the intended recipient, or a person responsible for delivering to the intended recipient, be advised that you have received this email in error and that any use is strictly prohibited.

      Random House Group + 44 (0) 20 7840 8400
      http://www.randomhouse.co.uk
      http://www.booksattransworld.co.uk
      http://www.kidsatrandomhouse.co.uk
      Generic email address - enquiries@...

      Name & Registered Office:
      THE RANDOM HOUSE GROUP LIMITED
      20 VAUXHALL BRIDGE ROAD
      LONDON
      SW1V 2SA
      Random House Group Ltd is registered in the United Kingdom with company No. 00954009, VAT number 102838980
      ***********************************************************************************

      [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

      [Non-text portions of this message have been removed]
    • sudhakar
      Thanks for the code. ... $result=mssql_query($sql);$num=mssql_num_rows($result); ...
      Message 2 of 9 , Nov 1, 2007
      • 0 Attachment
        Thanks for the code.

        --- Ankit Mathur <ankitmathur82@...> 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@yahoogroups.comFrom:
        > finals27@...: Sun, 28 Oct 2007 10:31:07
        > +0000Subject: [php-objects] 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
      Your message has been successfully submitted and would be delivered to recipients shortly.