Upload Excel xlsx File and Logic Hook

I have to upload a xlsx file into suitecrm, from a custom module, and after that, using a logic hook, read the file and using the information contained in this file on another module. But the SuiteCRM change the extension of files when save then, and because of that i can’t use phpExcel to read the file. Someone can help me?

Are you sure you can’t just tell it to read the file without an extension?

Any way, if you’re in a logic hook, you can just access the file and rename it for the temporary purpose of feeding it to that phpExcel library.

This might help you find your way around:

I try to rename the file to xlsx extension, but looks like that SuiteCRM encrypt the file or something like that, beacuse when i try open the file, i can’t.

I’ll see the text that you sent, thnks a lot!!

I found this: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.2/Architecture/Uploads/UploadFile/

I think that maybe help me!

Be careful with using Documentation for the newer SugarCRM versions, often it’s very different.

If you really need to use their Docs, I recommend going to the old manuals instead:

https://support.sugarcrm.com/Documentation/Unsupported_Versions/Sugar_6.7/

In this case, I checked and it seems there have been no changes so the article you found should still be current.

Thnks, but this didn’t work! I can’t be able to get the content of the file using this

Exactly which library are you using? PHPExcel? PhpSpreadsheet?

Can you see your file in the upload directory? If you list files ordered by date you should find one that is exactly the same number of bytes as your xlsx file, only it’s been renamed to a UUID like d1f618b5-5454-a5d7-9bdc-5b335bc86d97.

Make a note of that UUID.

(At this point, you can make a simple test: grab a copy of that file, move it to Windows, rename it to test.xlsx and try to open it in Excel, see if it works. If it does, then you can conclude the file’s integrity is ok.)

Now try make a simple PHP program, unrelated to SuiteCRM, that uses the phpExcel library that opens that file. Once you have that working, you can try moving your code into SuiteCRM (in the logic hook).

There might be issues specific to the library, like this one or anything like that, so it’s useful to break the problem down in parts.

2 Likes

It works, thnks a lot!!!

Great :tada:!

Do you want to share your solution here? I guess it might be helpful for others in the future: how to grab a value from an uploaded Excel file seems like a valuable feature to me.

For sure!

require 'C:/xampp/htdocs/PHPExcel/Classes/PHPExcel.php';

copy('C:/xampp/htdocs/crmGoAhead/upload/'.$id, 'C:/xampp/htdocs/crmGoAhead/upload/Deal Desk/Agenciamento/'.$name.'-'.$fornecedor.'.xlsx');

	$inputFileName = 'C:/xampp/htdocs/crmGoAhead/upload/Deal Desk/Agenciamento/'.$name.'-'.$fornecedor.'.xlsx';

try{
	$inputFileType  =   PHPExcel_IOFactory::identify($inputFileName);
	$objReader      =   PHPExcel_IOFactory::createReader($inputFileType);
	$objPHPExcel    =   $objReader->load($inputFileName);

}catch(Exception $e){
	die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestColumn();

for ($row = 1; $row <= $highestRow; $row++)
	{ 

	$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
									NULL,
									TRUE,
									FALSE);
}
2 Likes

I think this will be a nice addition to the Show and tell category!!

You’re right, I renamed the topic and moved it there. :+1:

1 Like

@gabriells1234

Which version of SuiteCRM do you use?