onethink匯出excel

來源:互聯網
上載者:User

標籤:儲存格   excel   content   for   factor   header   table   tin   cell   

function customer_daochu()    {         /**         * 客戶名單匯出         *         */        $customer = D(‘WcoaUCustomers‘);        $data = $customer->join("customers_system p on customers.customersid = p.customers_system_id ")->field("customersid,customername,customercode,phone,belong_deptid,belong_employeesid")->select();        $list = array();        $list1 = array();        foreach($data as $v)        {            $list1[0] = $v[‘customersid‘];            $list1[1] = $v[‘customername‘];            $list1[2] = $v[‘customercode‘];            $list1[3] = $v[‘phone‘];            $dept = D(‘Dept‘)->field(‘deptname‘)->where("deptid = {$v[‘belong_deptid‘]}")->find();            $list1[4] = $dept[‘deptname‘];            $em = D(‘Employees‘)->field(‘employeename‘)->where("employeesid = {$v[‘belong_employeesid‘]}")->find();            $list1[5] = $em[‘employeename‘];            array_push($list,$list1);        }        $headArr = array(‘id‘,‘姓名‘,‘編號‘,‘手機‘,‘所屬部門‘,‘所屬員工‘);        $fileName = "customer";        $this->exportExcel($fileName,$headArr,$list);    }public function exportExcel($expTitle,$expCellName,$expTableData)        //$expTitle=>表的主題,$expCellName=>表頭名(列名),$expTableData=>資料(以下採用數字索引數組)    {        $xlsTitle = iconv(‘utf-8‘, ‘gb2312‘, $expTitle);//檔案名稱        $fileName = ‘客戶表‘.date(‘_YmdHis‘);//or $xlsTitle 檔案名稱可根據自己情況設定        $cellNum = count($expCellName);        //多少列        $dataNum = count($expTableData);        //多少行        Vendor("PHPExcel");               $objPHPExcel = new \PHPExcel();            //初始化        $cellName = array(‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘,‘G‘,‘H‘,‘I‘,‘J‘,‘K‘,‘L‘,‘M‘,‘N‘,‘O‘,‘P‘,‘Q‘,‘R‘,‘S‘,‘T‘,‘U‘,‘V‘,‘W‘,‘X‘,‘Y‘,‘Z‘,‘AA‘,‘AB‘,‘AC‘,‘AD‘,‘AE‘,‘AF‘,‘AG‘,‘AH‘,‘AI‘,‘AJ‘,‘AK‘,‘AL‘,‘AM‘,‘AN‘,‘AO‘,‘AP‘,‘AQ‘,‘AR‘,‘AS‘,‘AT‘,‘AU‘,‘AV‘,‘AW‘,‘AX‘,‘AY‘,‘AZ‘);                $objPHPExcel->getActiveSheet(0)->mergeCells(‘A1:‘.$cellName[$cellNum-1].‘1‘);//合併儲存格        $objPHPExcel->setActiveSheetIndex(0)->setCellValue(‘A1‘, $fileName);    //標題         for($i=0;$i<$cellNum;$i++){            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].‘2‘, $expCellName[$i]);     //表頭(列名)        }           // Miscellaneous glyphs, UTF-8           for($i=0;$i<$dataNum;$i++){          for($j=0;$j<$cellNum;$j++){            $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), $expTableData[$i][$j]);            //內容          }                     }        //可以改格式,剩下不懂了        header(‘pragma:public‘);        header(‘Content-type:application/vnd.ms-excel;charset=utf-8;name="‘.$xlsTitle.‘.xlsx"‘);        header("Content-Disposition:attachment;filename=$fileName.xlsx");//attachment新視窗列印inline本視窗列印        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel2007‘);          $objWriter->save(‘php://output‘);         exit;       }

PHPExcel的存放位置跟匯入excel位置一樣!

onethink匯出excel

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.