Friday, 7 December 2012

How to generate excel in php

How to Generate Excel in php, its so much simple, so dont be frustrate. Just see below.

<?php
include('PHPExcel.php');

$worksheet=new PHPExcel();

$worksheet->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");
      
        /* Set the cells values */
      
        $i=1;
             $worksheet->setActiveSheetIndex(0)

                                           ->setCellValue('A'.$i,"Sr no.")

           ->setCellValue('B'.$i,"Date")
        
           ->setCellValue('C'.$i,"Sales")
        
           ->setCellValue('D'.$i,"Partners")
        
           ->setCellValue('E'.$i,"Refund")
        
           ->setCellValue('F'.$i,"Net Sales")
        
           ->setCellValue('G'.$i,"Sales")
        
           ->setCellValue('H'.$i,"Eps")
        
           ->setCellValue('I'.$i,"%Q")
        
           ->setCellValue('J'.$i,"%R")
        
           ->setCellValue('K'.$i,"%TTL")
        
           ->setCellValue('L'.$i,"Reg")
        
           ->setCellValue('M'.$i,"Epr")
        
           ->setCellValue('N'.$i,"%Q")
        
           ->setCellValue('O'.$i,"%TTL")
        
           ->setCellValue('P'.$i,"Qual")
        
           ->setCellValue('Q'.$i,"Epq")
        
           ->setCellValue('R'.$i,"%Q")
           ->setCellValue('S'.$i,"Not Qual")
        
           ->setCellValue('T'.$i,"%TTL")
        
           ->setCellValue('U'.$i,"TTL");
         
         
         
header('Content-Type: application/vnd.ms-excel');

header('Content-Disposition: attachment;filename="dailySales.xls"');

header('Cache-Control: max-age=0');



$objWriter = PHPExcel_IOFactory::createWriter($worksheet, 'Excel5');

$objWriter->save('php://output');

exit;

?>        


You can download link the Code from this link(Download)

No comments:

Post a Comment