PHP implementation using Phpexcel to export data _php tutorial

Source: Internet
Author: User
No more nonsense, just go to the code.
Copy CodeThe code is as follows:
Public Function Export_data ($data = Array ())
{
# code ...
Include_once (app_path. ' tools/phpexcel/classes/phpexcel/writer/iwriter.php ');
Include_once (app_path. ' tools/phpexcel/classes/phpexcel/writer/excel5.php ');
Include_once (app_path. ' tools/phpexcel/classes/phpexcel.php ');
Include_once (app_path. ' tools/phpexcel/classes/phpexcel/iofactory.php ');
$obj _phpexcel = new Phpexcel ();
$obj _phpexcel->getactivesheet ()->setcellvalue (' A1 ', ' Key ');
$obj _phpexcel->getactivesheet ()->setcellvalue (' B1 ', ' Value ');
if ($data) {
$i = 2;
foreach ($data as $key = = $value) {
# code ...
$obj _phpexcel->getactivesheet ()->setcellvalue (' a '. $i, $value);
$i + +;
}
}

$obj _writer = Phpexcel_iofactory::createwriter ($obj _phpexcel, ' Excel5 ');
$filename = "Outexcel.xls";

Header ("Content-type:application/force-download");
Header ("Content-type:application/octet-stream");
Header ("Content-type:application/download");
Header (' Content-disposition:inline;filename= '. $filename. ' ');
Header ("Content-transfer-encoding:binary");
Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT");
Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0");
Header ("Pragma:no-cache");
$obj _writer->save (' php://output ');
}

http://www.bkjia.com/PHPjc/328158.html www.bkjia.com true http://www.bkjia.com/PHPjc/328158.html techarticle no more nonsense, just on the code. Copy the code as follows: Public function export_data ($data = Array ()) {# code ... include_once (app_path. ' Tools/phpexce L/classes/phpexcel/writ ...

  • Related Article

    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.