Yii Framework Forum: Xphpexcel Exteneion : Not Working In Export Phpfile To Excel.yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Xphpexcel Exteneion : Not Working In Export Phpfile To Excel.yii Rate Topic: -----

#1 User is offline   Janvi Kapopara 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 13-January 14

Posted 19 September 2014 - 12:50 AM

HI,

i am using export data thru excel using extension:PHPExcel with XPHPExcel.
when i am set my reportfile in that code ,it will not support.gives an error..
my extension path is:
/var/www/html/edusec_temp/demo/protected/extensions/phpexcel
and in phpexcel folder :vendor folder,XPHPExcel.php ,README.md file

in my controller file action code is given below...
 public function actionCreateExcel()
  {
	Yii::import('ext.phpexcel.XPHPExcel');      
       $phpExcel = XPHPExcel::createPHPExcel();
 	
      $objPHPExcel= XPHPExcel::createPHPExcel();
      $objPHPExcel->getProperties()->setCreator("Janvi")
                             ->setLastModifiedBy("Janvi Kapopara")
                             ->setTitle("Report")
                             ->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()
		    ->getDefaultStyle()
		    ->getNumberFormat()
		    ->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT);



// Add some data

/*
$objPHPExcel->setActiveSheetIndex(0)
	    ->setCellValue('A1', 'Report')
            ->setCellValue('B2', 'Rudra ch!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!')
	    ->setCellValue('E2','Janvi Kapopara')
	    ->setCellValue('F2','5/6')
	    ->setCellValue('F3','4864546546546549843546546546574654654654654654654')
	    
	    ->setCellValue('G2','20-08-2014');
 
// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A4', 'janvi')
            ->setCellValue('A5', 'hello janvi')
	    ->setCellVAlue('B6','8/5');
		 
 
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
 
 
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

*/

// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML(); 
$objPHPExcel = $reader->load('/var/www/html/edusec_temp/bapucollege/protected/views/report/test.php'); 

// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('excelfile.xlsx');

$cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_discISAM;
$cacheSettings = array( 'dir'  => '/usr/local/tmp' // If you have a large file you can cache it optional
                      );
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
/** connection with the database 1.0 */
    $dbhost = "localhost";
    $dbuser = "root";
    $dbpass = "ubuntu";
    $dbname = "bapu_25082014";
    mysql_connect($dbhost,$dbuser,$dbpass);
    mysql_select_db($dbname);
$org_id = Yii::app()->user->getState('org_id');
$branch=Yii::app()->user->getState('branch');

	$student=Yii::app()->db->createCommand()
                    ->select('student_transaction_id')
                    ->from('student_transaction st')
		    ->join('student_info stud_info', 'stud_info.student_info_transaction_id = st.student_transaction_id')
                    ->where(' st.student_transaction_organization_id='.$org_id.' AND st.student_transaction_detain_student_flag NOT IN (1,2) order by stud_info.student_enroll_no ASC')
                    ->queryAll();
 		foreach($student as $s )
                {      
                    $sid[]=$s['student_transaction_id'];
                }
	if ($sid) {
/** Create a new PHPExcel object 1.0 */
   $objPHPExcel = new PHPExcel();
   $objPHPExcel->getActiveSheet()->setTitle('Data');
   }  
/** Loop through the result set 1.0 */
    $rowNumber = 1; //start in cell 1
    //while ($row = mysql_fetch_row($sid))
	foreach ($sid as $s) {
       $col = 'A'; // start at column A
       foreach($sid as $cell) {
          $objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell);
          $col++;
       }
       $rowNumber++;
}
  

$objReader = new PHPExcel_Reader_HTML();
$objPHPExcel = @$objReader->load('/var/www/html/edusec_temp/bapucollege/protected/views/report/test.html');

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="ExportProduseOportunitati.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');


 
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
 
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
      Yii::app()->end();
}





when i run this it gives me an error :

" DOMDocument::loadHTMLFile() expects exactly 1 parameter, 2 given "

i have create my test.php file and put the data in it as:
 <?php

$inputFileType = 'HTML';
$inputFileName = './myHtmlFile.html';
$outputFileType = 'Excel2007';
$outputFileName = './myExcelFile.xlsx';

$objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objPHPExcelReader->load($inputFileName);

$objPHPExcelWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$outputFileType);
$objPHPExcel = $objPHPExcelWriter->save($outputFileName);


?>


pls suggest some solution pls... i ve to complete this..
thanks
Thanks in advance.
With Regards,
Janvi
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users