phpexcel 生成大于26列数据

function excelExport2($fileName = '', $headArr = [], $data = [], $widths=[]) {
    ob_clean();
//    $fileName = iconv("UTF-8", "GB2312//IGNORE", @$fileName);
    $fileName .=".xls";
    Loader::import('PHPExcel.PHPExcel');
    Loader::import('PHPExcel.PHPExcel.IOFactory.PHPExcel_IOFactory');
    $objPHPExcel = new \PHPExcel();
    $objPHPExcel->getProperties();
    $key = 0;
    foreach ($headArr as $k=>$v) {
        $colum = PHPExcel_Cell::stringFromColumnIndex($k);
        $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($colum.'1', $v);
        $key += 1;
    }

    $column = 2;
    $objActSheet = $objPHPExcel->getActiveSheet();
    foreach($data as $key => $rows){ //行写入
        $span = 0;
        foreach($rows as $keyName=>$value){// 列写入
            $j = PHPExcel_Cell::stringFromColumnIndex($span);
            //$objActSheet->setCellValue($j.$column, $value);
            $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($j.$column, $value,\PHPExcel_Cell_DataType::TYPE_STRING);
            $span++;
        }
        $column++;
    }

    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    header('Content-Type: application/vnd.ms-excel');//告诉浏览器将要输出excel03文件
    header('Content-Disposition: attachment;filename="'.$fileName.'"');//告诉浏览器将输出文件的名称(文件下载)
    header('Cache-Control: max-age=0');//禁止缓存
    $objWriter->save("php://output");
}

 

 

//格式转换 小黑云转成ERP
    public function format_conversion(){
        set_time_limit(0);
        $serial_number=input('param.serial_number');
        $name=input('param.name');
          $list=Db::name('haohuo_order')->where(['serial_number'=>$serial_number])->select();
          if(count($list) && is_array($list)){
              $exportData=[];
              foreach ($list as $k=>$v){
                    $arr=array('43',trim($v['order_sn']),$v['goods_name'],$v['order_person'],$v['order_person'],$v['province'],$v['city'],
                        $v['area'],$v['address'],'000000',$v['order_mobile'],'0',$v['remark'],
                        $v['order_time'],$v['order_time'],'','60',$v['goods_model'],'',
                        $v['order_amount'],$v['order_num'],'','0','0','0'
                        );
                  $exportData[]=$arr;
              }
            $filename = $name.'-Erp'.$serial_number;
            $header = array(
                "店铺编码", "交易编号", "交易标题", "买家会员号", "收货人的姓名", "收货人的所在省份","收货人的所在城市",
                "收货人的所在地区", "收货人的详细地址", "收货的人邮编", "收货人的手机号码", "是否开票","卖家备注",
                "交易时间", "付款时间", "交易促销信息", "快递公司编码","商品编码","商品名称", "商品价格","购买数量",
                "发货仓库", "是否折扣", "是否运费","是否赠品");
            $widths = array();
            if ($exportData) {
                excelExport2($filename, $header, $exportData, $widths);//生成数据
                die();
            }
          }
    }

 

posted on 2019-06-11 09:09  长不大的菜鸟  阅读(...)  评论(...编辑  收藏

导航