Welcome Guest, Not a member yet? Register   Sign In
Install Library Phpspreadsheet via Composoer Autoload not working?
#1
Question 

I just installed Phpoffice/Phpspreadsheet via Composer but I can't create new instance of this library. I've checked in the composer.json file, there is already a phpspreadsheet in require.

But when I try to create a new instance, There's an error "Undefined type 'PhpOffice\PhpSpreadsheet\Reader\Xlsx'".

Please help me to find out what's wrong.
Reply
#2

Can you show how you used it on your code? Maybe you are missing the use statement?
Reply
#3

(09-25-2020, 09:12 AM)paulbalandan Wrote: Can you show how you used it on your code? Maybe you are missing the use statement?
Code:
public function readerXlsx()
{
// Create instance of Phpspreadsheet
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); //And this instance show an error "Undefined type ...."

}

I follow the same way as in the documentation to create instances to write a phpspreadsheet.
Reply
#4

(This post was last modified: 09-30-2020, 07:52 PM by John_Betong.)

@mrardiyansyah,

I have been using a plain PHP application and PHP Spreadsheet for quite a few years.

I have PhpSpreadsheet installed in /var/www/ci2/vendor and use the following script to create a new instance:

PHP Code:
require '/var/www/ci2/vendor/autoload.php';  
    
use PhpOffice\PhpSpreadsheet\Spreadsheet;
    use PhpOffice\PhpSpreadsheet\Writer\Xlsx;


//==============================================
PRIVATE function _convertXlsToCsv
(
  
string $xls
  
string $csv
)
:
bool
{
  
$result FALSE;

  try {
    
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($xls);
    
$writer = new  \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet);
    
$writer->setUseBOM(true);
    
$writer->save($csv);
  }catch (
Exception $e){
    
print_r($e->message(), '$e->message()''red');
  }
  
$result file_exists($csv);

  return 
$result;
}
// 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB