How to download data to excel file?

4 replies
Hello everyone! How do you write a PHP function in codeigniter that lets user download data to an Excel file?


Thank You.
#data #download #excel #file
  • Profile picture of the author ussher
    first you download codeigniter and connect it to the database and output the code in the format you require.
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5733480].message }}
  • Profile picture of the author MikerMix
    You could do this?
    Signature

    :)

    {{ DiscussionBoard.errors[5733655].message }}
    • Profile picture of the author jmartinez
      I'm not sure exactly what you are trying to do, but you can filter the data into .csv format using php and then dynamically create a file on the server that can be downloaded.
      {{ DiscussionBoard.errors[5743358].message }}
  • Profile picture of the author devnty06
    Code:
    <?PHP function cleanData(&) 
    {
      = preg_replace("/t/", "t", );
      = preg_replace("/r?n/", "n", );
     if(strstr(, '"'))  = '"' . str_replace('"', '""', ) . '"';
    } 
    # filename for download
     = "website_data_" . date('Ymd') . ".xls";
    header("Content-Disposition: attachment; filename=""");
    header("Content-Type: application/vnd.ms-excel"); 
    0 = false; 
    foreach( as ) 
    { 
    if(!0) 
    {
     # display field/column names as first row 
     echo implode("t", array_keys()) . "rn";
     0 = true;
    } 
    array_walk(, 'cleanData'); 
    echo implode("t", array_values()) . "rn"; 
    }
     exit;
    ?>
    {{ DiscussionBoard.errors[5747516].message }}

Trending Topics