2016-06-23 8 views
0

でExcelシートを生成し、私のコントローラであるがあれば、私はExcelシートを生成したい、しかし、私は見出しせずに値のみを取得しています、誰もがスタイルで列の値を与える方法に私を助けることができるのCodeIgniter

public function generateexcel() 
{ 
    require_once("PHPExcel/Classes/PHPExcel.php"); 
     $objPHPExcel = new PHPExcel(); 
     $objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')->setSize(12); 
     $objRichText = new PHPExcel_RichText(); 
     $objRichText->createText("Students"); 
     $objRichText = new PHPExcel_RichText(); 
     $objRichText->createText("Student Details"); 
     $students = $this->student->getstudents; 
     $objPHPExcel->getActiveSheet()->fromArray($students); 
     $filename = "students.xls"; 
     $objPHPExcel->getActiveSheet()->setTitle('Students'); 
     $objPHPExcel->setActiveSheetIndex(0); 
     header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); 
     header("Content-Disposition: attachment;filename=\"".$filename."\";"); 
     header("Cache-Control: max-age=0"); 
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
     $objWriter->save('php://output'); 


} 

答えて

0

あなたは返事をそんなにこの

$this->load->library('excel'); 

$filename = 'tab'; 
    $title = 'title name'; 
    $file = $filename . '-' . $name . '.xls'; //save our workbook as this file name 
    $query = $his->model->function($params); 

    header('Content-Type: application/vnd.ms-excel'); //mime type 
    header('Content-Disposition: attachment;filename="'.$file.'"'); //tell browser what's the file name 
    header('Cache-Control: max-age=0'); //no cache 

    $this->excel->setActiveSheetIndex(0); 
    $this->excel->getActiveSheet()->setTitle($filename); 
    $this->excel->getActiveSheet()->setCellValue('A1', $title); 
    $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20); 
    $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); 
    $this->excel->getActiveSheet()->mergeCells('A1:' . $cell . '1'); 
    $this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); 

    $this->excel->getActiveSheet()->setCellValue('A2', 'Subtitulo 1'); 
    $this->excel->getActiveSheet()->setCellValue('B2', 'Subtitulo 2'); 
    $this->excel->getActiveSheet()->setCellValue('C2', 'Subtitulo 3'); 
    $this->excel->getActiveSheet()->setCellValue('D2', 'Subtitulo 4'); 
    $this->excel->getActiveSheet()->setCellValue('E2', 'Subtitulo 5'); 
    $this->excel->getActiveSheet()->getStyle('A2:E2')->getFont()->getColor()->setRGB('555555'); 
    $this->excel->getActiveSheet()->getStyle('A2:E2')->getFont()->setSize(10); 
    $this->excel->getActiveSheet()->getStyle('A2:E2')->getFont()->setBold(true); 

    $i = 3; 
    foreach($query as $item){ 
     $this->excel->getActiveSheet()->setCellValue('A'.$i, $item['cell1']); 
     $this->excel->getActiveSheet()->setCellValue('B'.$i, $item['cell2']); 
     $this->excel->getActiveSheet()->setCellValue('C'.$i, $item['cell3']); 
     $this->excel->getActiveSheet()->setCellValue('D'.$i, number_format($item['cell4'], 0, ',', '.')); 
     $this->excel->getActiveSheet()->setCellValue('E'.$i, date('d M Y h:i a', strtotime($item['date1']))); 

     //$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(10); 
     $this->excel->getActiveSheet()->getColumnDimension('A')->setAutoSize(TRUE); 
     $this->excel->getActiveSheet()->getColumnDimension('B')->setAutoSize(TRUE); 
     $this->excel->getActiveSheet()->getColumnDimension('C')->setAutoSize(TRUE); 
     $this->excel->getActiveSheet()->getColumnDimension('D')->setAutoSize(TRUE); 
     $i++; 
    } 

    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); 
    $objWriter->save('php://output'); 
+0

ありがとうを試し、DBからの情報にExcelファイルをcreataしたいuが私を助けることができる統合し、あなたはそのは、サーバーエラーとしてダウンロードし、その表示されていない@elddenmedio申し訳@elddenmedio – ohmygood

+0

をお知らせします私のコードで何が間違っている – ohmygood

+0

は何ですrエラー? – elddenmedio

関連する問題

 関連する問題