• php导出excel


      今天做的时候发现有好多答案,很乱,所以就整理了一个,以便下回使用

    js代码

    $("#excel").click(function(){
    var _date=$("#date").val();
    var _id=$("#date").attr('group_id');
    window.location.href="groupbuying.php?act=group_info&date="+_date+"&id="+_id+"&type=excel";
    php代码
    include './phpexcel1/Classes/PHPExcel.php';
    $excel = new PHPExcel();
    //列数
    $letter = array('A','B','C','D','E','F','G','H','I','J','K');
    //表头
    $tableheader = array('商品名称','国条码','商品口味','进货数量','进货价','销售价','销售额','下单时间','区域','买家名称','供应商名称');
    for($i = 0;$i < count($tableheader);$i++) {
    $excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
    }
    //给表赋值 这里的info 换成相应的数组
    for ($i = 2;$i <= count($info) + 1;$i++) {
    $j = 0;
    foreach ($info[$i - 2] as $key=>$value) {
    $excel->getActiveSheet()->setCellValue("$letter[$j]$i","$value");
    $j++;
    }
    }
    $write = new PHPExcel_Writer_Excel5($excel);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
    header("Content-Type:application/force-download");
    header("Content-Type:application/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header('Content-Disposition:attachment;filename="'.$group_id.'.xls"');
    header("Content-Transfer-Encoding:binary");
    $write->save('php://output');exit;
    
    
  • 相关阅读:
    多表查询练习
    mysql查询练习
    mysql建表练习
    超详细mysql left join,right join,inner join用法分析
    Elasticsearch搜索引擎版本配置
    centos 开启apache rewrite模式
    centos 下 apache 重启启动命令
    centos 下使用sublime
    ThinkPHP Where 条件中使用表达式
    转载自php100中文网 centos下lamp 环境搭建
  • 原文地址:https://www.cnblogs.com/liyunchao/p/7365278.html
Copyright © 2020-2023  润新知