php code "export table to excel"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amrhi
    New Member
    • Sep 2006
    • 22

    php code "export table to excel"

    Hello Guys,....!
    Can you help me how to export my table to excell using php code ..?
    thanks alot
  • aniltc
    New Member
    • Jul 2006
    • 17

    #2
    You should use pear spread sheet
    download pear spread sheet and use the below code
    [PHP]
    <?php
    /*
    $Id: report_all.php, v 1.1 2004/08/30 16:03:40 chris Exp $
    generate a spreadsheed from and addressbook in mysql database.
    */

    include "dblib.php" ;
    DBConnect();

    require_once 'Spreadsheet/Excel/Writer.php';

    $workbook = new Spreadsheet_Exc el_Writer();
    $format_bold =& $workbook->addFormat();
    $format_bold->setBold();

    $worksheet =& $workbook->addWorksheet() ;
    $worksheet->write(0, 0, "name", $format_bold);
    $worksheet->write(0, 1, "address", $format_bold);
    $worksheet->write(0, 2, "phone", $format_bold);
    $worksheet->write(0, 3, "email", $format_bold);
    $worksheet->write(0, 4, "comments", $format_bold);

    # start by opening a query string
    $fullquery="sel ect * from smslog";

    $result=mysql_d b_query($db_nam e,$fullquery);

    $i=1;
    while($row=mysq l_fetch_assoc($ result)){
    $worksheet->write($i, 0, "$row[name]");
    $worksheet->write($i, 1, "$row[address]");
    $worksheet->write($i, 2, "$row[phone]");
    $worksheet->write($i, 3, "$row[email]");
    $worksheet->write($i, 4, "$row[comments]");
    $i++;
    }
    $workbook->send('test.xls ');
    $workbook->close();
    ?>[/PHP]
    I hope this will solve your problem

    Comment

    • amrhi
      New Member
      • Sep 2006
      • 22

      #3
      thanks alot you're amazing.
      regards

      Comment

      Working...