PHPExcel:MySQL数据导出excel

<?php
error_reporting(0);
        date_default_timezone_set('Europe/London');
        /** PHPExcel */
        require_once './Classes/PHPExcel.php';
// Create new PHPExcel object  
        $objPHPExcel = new PHPExcel();
// Set properties  
        $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                ->setLastModifiedBy("Maarten Balliauw")
                ->setTitle("Office 2007 XLSX Test Document")
                ->setSubject("Office 2007 XLSX Test Document")
                ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
                ->setKeywords("office 2007 openxml php")
                ->setCategory("Test result file");
        $objPHPExcel->getActiveSheet()->mergeCells('A1:G1');
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
  //调单元格宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
// Add some data 
        $objPHPExcel->setActiveSheetIndex(0)
                 ->setCellValue('A2', "转盘币产出")
                ->setCellValue('B2', '猜奖币产出')
                ->setCellValue('C2', '签到币产出')
                ->setCellValue('D2', '邀请币产出')
                ->setCellValue('E2', '摇摇币产出')
                ->setCellValue('F2', '任务币产出')
                ->setCellValue('G2', '购买币产出')
                ->setCellValue('H2', '分享币产出')
                ->setCellValue('I2', '下载游戏')
                ->setCellValue('J2', '活动奖励')
                ->setCellValue('K2', '总金币产出')
                ->setCellValue('L2', '转盘币消耗')
                ->setCellValue('M2', '兑换礼品币消耗')
                ->setCellValue('N2', '兑换话费币消耗')
                ->setCellValue('O2', '猜奖币消耗')
                ->setCellValue('P2', '总金币消耗');
        
       
                $l1 = "A3";
                $l2 = "B3";
                $l3 = "C3";
                $l4 = "D3";
                $l5 = "E3";
                $l6 = "F3";
                $l7 = "G3";
                $l8 = "H3";
                $l9 = "I3";
                $l10 = "J3";
                $l11 = "K3";
                $l12 = "L3";
                $l13 = "M3";
                $l14 = "N3";
                $l15 = "O3";
                $l16 = "P3";
               
    
                $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue($l1, 55)
                        ->setCellValue($l2, 55)
                        ->setCellValue($l3, 44)
                        ->setCellValue($l4, 55)
                        ->setCellValue($l5,55)
                        ->setCellValue($l6, 55)
                        ->setCellValue($l7, 55)
                        ->setCellValue($l8, 55)
                        ->setCellValue($l9, 55)
                        ->setCellValue($l10, 55)
                        ->setCellValue($l11, 55)
                        ->setCellValue($l12, 55) 
                        ->setCellValue($l13, 55)
                        ->setCellValue($l14, 55)
                        ->setCellValue($l15, 55)
                        ->setCellValue($l16, 55);
        // Rename sheet  
        $objPHPExcel->getActiveSheet()->setTitle('运营数据统计2015');
        // Set active sheet index to the first sheet, so Excel opens this as the first sheet  
        $objPHPExcel->setActiveSheetIndex(0);
        // Redirect output to a client’s web browser (Excel5)  
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="运营数据统计.xls"');
        header('Cache-Control: max-age=0');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;

你可能感兴趣的:(PHPExcel:MySQL数据导出excel)