Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I tried to import excel content using :
module_load_include('inc', 'phpexcel');
// The path to the excel file
$path = 'sites/default/files/export.xls';
$result = phpexcel_import($path);
if (is_array($result)) {
drupal_set_message(t("We did it !"));
}
else {
drupal_set_message(t("Oops ! An error occured !"), 'error');
}
in a view but it is showing "Oops ! An error occured !"
I have download the entire library (1.8.*) from Github and put it under sites/*/libraries/PHPExcel/ as well as made sure changelog.txt file is present.
I am new to drupal so I don't know where am going wrong. Can someone help me?
Comments
Comment #2
arunkumark@lakshmi
First Thanks for using this module.
Can you please confirm "export.xls" file is exist or not before processing. And also confirm given file is readable.
Try the below code may help useful to resolve your problem.
Comment #3
_lakshmi_ CreditAttribution: _lakshmi_ commented@arun I am getting the error : Oops ! An error occured !
Comment #4
arunkumarkCan you please detail your Problem.
Comment #5
_lakshmi_ CreditAttribution: _lakshmi_ commented@arun I executed the code that you suggested and it's showing error as "Oops ! An error occured !" as per
When I checked the configuration tab I noticed the error:
" One or more problems were detected with your Drupal installation. Check the status report for more information."
and the status report is showing
"PHPExcel >1.7.8
In order to use PHPExcel, you must first download the entire library (1.8.*) at Github and put it under sites/*/libraries/PHPExcel/ (so you should have sites/*/libraries/PHPExcel/Classes/PHPExcel.php). Make sure to include the changelog.txt file as well (sites/*/libraries/PHPExcel/changelog.txt), as Library API requires this file for loading the classes."
I tried pasting the entire library multiple times, restarted my local server multiple times,but still both errors are not resolving.
Comment #6
_lakshmi_ CreditAttribution: _lakshmi_ commented@arun The file path is being read but the content( a table of numbers ) is not getting read when I tried running the following code
Result is coming as
Notice: Array to string conversion in eval() (line 35 of C:\xampp\htdocs\drupal\modules\php\php.module(80) : eval()'d code).
Status message: We did it !
$result val: Array
Can you help me understand where am going wrong?
Comment #7
arunkumark@lakshmi,
Can you please confirm you are using this code inside any UI(PHP code in DB). If it is then please write in your custom modules. So, you can able to find out the exact error reason.
From your result, the XLS reading operation done properly. To access the result array values by their keys so you get the processed values.
Comment #8
_lakshmi_ CreditAttribution: _lakshmi_ commented@arun Thank you. Using
print_r($result);
I was able to view the content of the excel document.I made a content type with fields Title, Body and Upload(file field type) and a corresponding view. Am using the code inside an editor of this content type.
Comment #9
arunkumark@laskshmi Instead of writing code inside Editor try to write you own codes in your module files and call to your view.
Expecting that this problem resolved, Closing this issue.
Cheers!
Comment #10
_lakshmi_ CreditAttribution: _lakshmi_ commented@arun Thank you the problem is resolved.
I haven't tried making my own modules as am new to Drupal. Will look into it. thank you.