Using PHP to generate Excel files to a specified directory, _php tutorial

Source: Internet
Author: User

Use PHP to generate Excel files to the specified directory,


Recently the company wants to generate a report, generated in PHP.

Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename=test_data.xls");

I Baidu, seemingly this can be achieved soon, but this file is generated in the browser to download the place,

I want to generate the generated files to the specified directory, so can it be implemented?

Also, can I insert a picture inside?

Phpexcel is English, read for a long while not understand. Is there a direct-generated example to look at?

Below we enclose an example:

/** +----------------------------------------------------------* Import the required class library with Java's import * This function has the cache function +------------------ ----------------------------------------* @param string $class class Library namespace String * @param string $baseUrl start path * @param string $e XT import file name extension +----------------------------------------------------------* @return Boolen +--------------------------  --------------------------------*/function Import ($class, $baseUrl = ', $ext = '. class.php ') {static $_file = array ();  $class = str_replace (Array ('. ', ' # '), Array ('/', '. '), $class);  if (' = = = $baseUrl && false = = = Strpos ($class, '/')} {//Check alias import return Alias_import ($class);  } if (Isset ($_file[$class. $baseUrl])) return true;  else $_file[$class. $baseUrl] = true;  $class _strut = explode ('/', $class); if (empty ($BASEURL)) {if (' @ ' = = $class _strut[0] | |      App_name = = $class _strut[0]) {//Load the current Project Application class Library $BASEURL = DirName (Lib_path); $class = Substr_replace ($class, basename (lib_path). ' /', 0, StrleN ($class _strut[0]) + 1);      }elseif (' think ' = = Strtolower ($class _strut[0])) {//Think official base Class library $baseUrl = Core_path;    $class = substr ($class, 6); }elseif (In_array (Strtolower ($class _strut[0]), array (' org ', ' com ')) {//org third party public class library COM Enterprise public class Library $BASEURL = LIBR    Ary_path;      }else {//Load other Project Application class Library $class = Substr_replace ($class, "', 0, strlen ($class _strut[0]) + 1); $BASEURL = App_path. '.. /' . $class _strut[0]. '/'. basename (Lib_path). '    /';  }} if (Substr ($BASEURL,-1)! = '/') $baseUrl. = '/'; $classfile = $baseUrl. $class.  $ext;  if (!class_exists (basename ($class), false)) {//If the class does not exist import the class library file return Require_cache ($classfile); }}/*** Export Excel Table * @param array $data data, two-dimensional array, one record per piece of data * @param array $title The field name of each column of data, an array must be consistent with the data order (can be omitted) * @param string $fi Lename Excel Name * @param array $field need to specify the exported data field, the sort must match the title, that is, and the array key value */function exportexcel ($data = ", $title ="  , $filename = ' Excel ', $field =array ()) {if (! $data | |!is_array ($DATA)) return false; if ($filename== ') $filename = ' Excel ';    if ($field && Is_array ($field)) {//As long as the specified fields are exported and exported in this order $dateNew =array ();      foreach ($data as $k = $v) {foreach ($field as $fkey) {$dateNew [$k] [$fkey]= $v [$fkey];  }} $data = $dateNew;  } Import ("@.org.util.excelxml");//Call to export the Excel class $xls = new Excelxml (' UTF-8 ', false, ' Sheet1 ');  $xls->addarray ($data, $title); $xls->generatexml ($filename);}

http://www.bkjia.com/PHPjc/1020540.html www.bkjia.com true http://www.bkjia.com/PHPjc/1020540.html techarticle using PHP to generate Excel files to the specified directory, the company has recently generated a report, generated in PHP. Header ("Content-type:application/vnd.ms-excel"); Header ("Content-disposition:attachment;file ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.