Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By stevensi1018
#795993
I'm trying to use PHPExcel to read an excel file from a document in a variable with this trigger:
Code: Select all
if (isset(@@file_label) and @@file_label != '[]') {
   $filename = json_decode(@@file_label)[0];
   $fileId = json_decode(@@file)[0];
   $ext = pathinfo($filename, PATHINFO_EXTENSION);
        
   $d = new AppDocument();
   $aFile = $d->Load($fileId);
   $g = new G();
   $path = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP .
           $fileId .'_'. $aFile['DOC_VERSION'] .'.'. $ext;
   @@path = $path;
	
   @@require = require_once('/opt/Classes/PHPExcel.php');
   @@require2 = require_once('/opt/Classes/PHPExcel/IOFactory.php');
	    
   $inputFileType = PHPExcel_IOFactory::identify($path); //identify type of file 
   $oReader = PHPExcel_IOFactory::createReader($inputFileType);
   $oReader->setReadDataOnly(); //get data as plain text 
@@oReader = $oReader;
       
   try {
      $oExcel = $oReader->load($path);
      $aData = $oExcel->getActiveSheet()->toArray(null, true, true, true);
      //print "<pre>"; var_dump($aData); die; 
   } 
   catch (Exception $e) {
      $g->SendMessageText($e->getMessage(), 'ERROR');
   };
   
   if (count($aData) <= 1) {
      $g->SendMessageText("File $filename contains no data", 'WARNING');
   }
    @@value = $aData[1]['A'];
}  
But the code isn't working after ' $inputFileType = PHPExcel_IOFactory::identify($path); //identify type of file ' .... Is there something i did wrong ? I imported the 'Classes' folder from PHPExcel in /opt
User avatar
By programerboy
#795997
Hi,

I use this code and it work for me. Please test it:
Code: Select all
$uploaded_file_id = trim( @@file_excel_bimehshodeh, '["');
$uploaded_file_id = trim($uploaded_file_id, '"]');

if(!empty($uploaded_file_id)){
	$DOC_VERSION = 1;
	$oAppDocument = new AppDocument();
	$oAppDocument->Fields = $oAppDocument->load($uploaded_file_id, $DOC_VERSION);
	
	$ext = pathinfo($oAppDocument->Fields['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
	
	$app_uid = G::getPathFromUID($oAppDocument->Fields['APP_UID']);
	$file = G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $uploaded_file_id);
	
	$realPath = PATH_DOCUMENT .  $app_uid . '/' . $file[0] . $file[1] . '_' . $DOC_VERSION . '.' . $ext;
	$realPath1 = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '.' . $ext;
	
	if(file_exists($realPath) || file_exists($realPath1)){
		if(!file_exists($realPath) && file_exists($realPath1))
			$realPath = $realPath1;
		
		require_once('../engine/PHPExcel/PHPExcel.php');
		$excel_file_type = PHPExcel_IOFactory::identify($realPath);
		
		if($excel_file_type == 'Excel5' OR $excel_file_type = 'Excel2007'){
            $excel_reader = PHPExcel_IOFactory::createReader($excel_file_type);
			$excel_reader->setReadDataOnly(true);
			$excel = $excel_reader->load($realPath);
			$excel_file_creator = $excel->getProperties()->getCreator();
			$excel_file_created = $excel->getProperties()->getCreated();
			
			$excel_sheets_temp = $excel->getSheetNames();
			@=Excel_Sheets = array();
			foreach($excel_sheets_temp AS $key => $row){
				@=Excel_Sheets[] = array($key, $row);
			}
			
			@@Excel_File_PATH = $realPath;
            @@text_Excel_File_Name = $oAppDocument->Fields['APP_DOC_FILENAME'];
			@@text_Excel_File_Type = $excel_file_type;
			@@text_Excel_File_Creator = $excel_file_creator;
			@@datetime_Excel_File_Created = date('Y-m-d', $excel_file_created);
        }
	}
}
Thanks
By Arfaeram0511
#828742
Hi
I am trying to implement a similar functionality but it doesnt work. Could you help me out as when are you uploading the file I am doing it in a seperate dynaform and trying to read it in a different dynaform.
Are you doing it in the same dynaform

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]