【php】excel导出分sheet

Continue Read..
    /**
     * 导出export 生成多个sheet
     * $data = [
     *      'sheet1'=>[
     *          'header'=>['k'=>v],
     *          'date'=>['k'=>v],
     *      ]
     *      'sheet2'=>[
     *          'header'=>['k'=>v]
     *          'data'=>['k'=>v]
     *      ]
     * ]
     * header和data 用k 关联
     * @param unknown $data
     * @param string $user
     * @param string $format
     * @param string $title
     * @return multitype:mixed
     */  
    public function multiExportSheet($data, $user = 'admin', $format = false, $title = ''){
        require_once __DIR__.'/PHPExcel.php';
        $objPHPExcel = new \PHPExcel();
        $j = 0;
        foreach ($data as $dk=>$dv){
            if($j==0){
                $objPHPExcel->setActiveSheetIndex($j); //设置第一个工作表为活动工作表
                $objPHPExcel->getActiveSheet()->setTitle($dk); //设置工作表名称
            }else{
                $msgWorkSheet = new \PHPExcel_Worksheet($objPHPExcel, $dk); //创建一个工作表
                $objPHPExcel->addSheet($msgWorkSheet); //插入工作表
                $objPHPExcel->setActiveSheetIndex($j); //切换到新创建的工作表
            }
            
            $arrHeader = $dv['header'];
            $arrBody = $dv['data'];
            $newdata = [];
            
            $i = 0;
            foreach ($arrBody as $k=>$v){
                foreach ($arrHeader as $kk=>$vv){
                    if(!empty($v[$kk])){
                        if($kk == 'idcard' || $kk == 'bank_card'){
                            $newdata[$i][$kk] = $v[$kk]."\t";
                        }else{
                            $newdata[$i][$kk] = $v[$kk];
                        }
                    }else{
                        $newdata[$i][$kk] = "";
                    }
                }
                $i++;
            }
            $hd[0] = $arrHeader;
            $arrExcelInfo = array_merge($hd, $newdata);
            $objPHPExcel->getActiveSheet()->fromArray(
                $arrExcelInfo, // 赋值的数组
                NULL, // 忽略的值,不会在excel中显示
                'A1' // 赋值的起始位置
            );
            
            unset($arrExcelInfo);
            unset($hd);
            unset($arrHeader);
            unset($arrBody);
            unset($newdata);
            $j++;
        }
        
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    
        $result=[];
        $path = 'down/'.md5($user.'down').'/';
        $rootPath = $this->mkdirPath($path);
        $date = date('YmdHis');
    
        $title = $date.rand(10000,99999);
        $outputFileName = $rootPath.$title.".xlsx";
        $objWriter->save($outputFileName);
        $result[]= str_replace(APP_PATH, '', $outputFileName);
        return $result;
    }


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【linux】gitlab和nginx冲突的解决方案

Continue Read..

vim /etc/gitlab/gitlab.rb

external_url = 'http://IP或域名'

unicorn['listen'] = '127.0.0.1'

unicorn['port'] = 3002

nginx['listen_addresses'] = ['*']

nginx['listen_port'] = 3001


如果修改了 external_url 

需修改/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml中 host 和 port

 

vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
listen "127.0.0.1:3002", :tcp_nopush => true



vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
listen *:3001;




改完之后
先关闭gitlab的ngxin服务
gitlab-ctl stop nginx

然后开启自己的nginx服务
service nginx start

然后启动gitlab的nginx服务
gitlab-ctl start nginx


gitlab的访问地址就是 http://127.0.0.1:3001/users/sign_in

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权