PHPExcel生成excel

include 'statics/PHPExcel/PHPExcel.php';
            include 'statics/PHPExcel/PHPExcel/Writer/Excel5.php';
            $objPHPExcel = new PHPExcel();
            ini_set("memory_limit", "1024M"); // 設置php可以使用內存
            set_time_limit(0); 
            $objPHPExcel->getProperties()->setCreator($nickname)
                               ->setLastModifiedBy($nickname)
                               ->setTitle("數據EXCEL導出")
                               ->setSubject("數據EXCEL導出")
                               ->setDescription("備份查詢數據")
                               ->setKeywords("excel")
                              ->setCategory("result file");
            $objPHPExcel->getActiveSheet()->setCellValue('A1', '日期');
            $objPHPExcel->getActiveSheet()->setCellValue('B1', '反饋數量');
            $objPHPExcel->getActiveSheet()->setCellValue('C1', '反饋人數');
            /*$objPHPExcel->getActiveSheet()->setCellValue('Z1', '來源頁URL');*/
            if($feed){
                $i=2;
                foreach ($feed as $key => $v) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$tim[$key]);
                    $objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$v);
                    $objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$num[$key]);
                    $i++;
                }
            
                $objPHPExcel->getActiveSheet()->setTitle('反饋統計表');//重命名工做表
                $objPHPExcel->setActiveSheetIndex(0);//設置打開excel時顯示的工做表
                $callStartTime = microtime(true);
                $filename='PDT'.(date('Y-m-d,H:i:s'));
                header('Content-Type: application/vnd.ms-excel');  
                header('Content-Disposition: attachment;filename="'.$filename.'.xls"');  //日期爲文件名後綴  
                header('Cache-Control: max-age=0'); 
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                $objWriter->save('php://output');

 PHPExcel類庫下載地址:https://www.php.cn/xiazai/leiku/1491php

相關文章
相關標籤/搜索