Integrate PHPOffice in SuiteCRM

Dear,
Integrate phpOffice in SuiteCRM.
it’s really easy :

1- copy PHPOffice in custom/include folder
2- make a file with SQL

sample :



        $sSQL = "SELECT * FROM ACCOUNTS";
  	include('custom/include/excel.php');

3 - excel.php


require_once('custom/include/phpexcel/PHPExcel.php');

		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setCreator($current_user->name)
							 ->setLastModifiedBy($current_user->name)
							 ->setTitle("TITLE")
							 ->setSubject("SUBJECT")
							 ->setDescription("DESCRIPTION")
							 ->setKeywords("KEYWORD")
							 ->setCategory("CATEGORY");

		$result = $GLOBALS['db']->query($sSQL);
		$objPHPExcel->setActiveSheetIndex(0);
		$rowCount = 1;
		while($row = $GLOBALS['db']->fetchByAssoc($result) )
		{	
			$col = 0;
    		foreach($row as $key=>$value) {
    			if ($rowCount == 1){
        			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $rowCount, $key);
        			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $rowCount+1, $value);
        		}else{
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $rowCount, $value);
        		}
        		$col++;
    		}
			if ($rowCount == 1) $rowCount =2;
    		$rowCount++;	
    	}
            
		$objPHPExcel->getActiveSheet()->setTitle('EXCEL');
		$objPHPExcel->setActiveSheetIndex(0);	
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="doc.xlsx"');
		header('Cache-Control: max-age=0');
		header('Cache-Control: max-age=1');
		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, 'Excel2007');
		$objWriter->save('php://output');
		exit;

It’s really easy, is there a way for SuiteCRM Teams to integrate it on the menu where we can select/…export mass update menu on all list view.

Here another sample with docx template :



		\PhpOffice\PhpWord\Autoloader::register();
		$PHPWord = new \PhpOffice\PhpWord\PhpWord();
		
		$meeting = BeanFactory::getBean('Meetings', $this->bean->id);	
		$account = BeanFactory::getBean('Accounts', $meeting->parent_id);
		$document = $PHPWord->loadTemplate('custom/include/PS_FR.docx');
		require_once('custom/modules/Meetings/pv_data.php');

pv_data.php


$numero = substr($meeting->name , -2);
		$document->setValue('NUMERO', $numero);	
		
		$document->setValue('DATE_MEETING', $meeting->date_start);
		$document->setValue('MEETING_LOCATION', $meeting->location);
                ……

$file_name =  trim('RC-' .ucfirst(strtolower($account->name))  .'-' .$year .$month .$day .'-' .$numero);
		$temp_file = tempnam(sys_get_temp_dir(), $file_name);
		$document->saveAs($temp_file);
		sleep(1); 
		if(!$temp_file) {     
        	die('file not found'); 
    	}else {     
        	header("Cache-Control: public");
        	header('Content-Description: File Transfer');
			header('Content-Type: application/octet-stream');        
        	header('Content-Transfer-Encoding: binary');  
        	header("Content-Disposition: attachment; filename=\"$file_name.docx\"");    
        	header("Content-Transfer-Encoding: binary"); 
        	header('Cache-Control: max-age=0');
        	header('Pragma: no-cache');
        	header('Expires: 0');
        	header('Content-Length: '.filesize($temp_file));      
        	   
        	readfile($temp_file); 
        	flush(); 
    	}
    	unlink($temp_file);
    	exit;

In this sample, i use a template (docx) where all is formatted and in put value in variable.
Of course, in the same way, we can create new document from scratch.

Regards

Hello ! @item buddy I’m also trying the same to integerate the php office in suitecrm could you able to help me so that i can able to understand , the details you have given above is not enough for me to understand the process so please help me to get out of it. Thanks in advance