• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
phpspreadsheet in Codeigniter4

#1
Hi folks,

I am new in codeigniter 4, when needed to manipulate some excel files in my app I found the phpspreadsheet library convenient for that. However, after installing it using  composer I found it difficult to implement it in my app. 


Even when I tested their example hereafter couldn't work instead displayed 

<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');

require(vendor/autoload.php): failed to open stream: No such file or directory 


I need a help on how to set it up and use it in my app.


Attached Files Thumbnail(s)
   
Reply

#2
Hi, CI4 already knows where composer are located. This is how you load it inside an controller

PHP Code:
<?php
namespace App\Controllers;

use \
PhpOffice\PhpSpreadsheet\Spreadsheet;
use \
PhpOffice\PhpSpreadsheet\Writer\Xlsx;

class 
Example extends BaseController
{
    public function 
index()
    {
        
$spreadsheet = new Spreadsheet();
        
$sheet $spreadsheet->getActiveSheet();
        
$sheet->setCellValue('A1''Hello World !');
        
$writer = new Xlsx($spreadsheet);
        
$writer->save('hello world.xlsx');
    }


PS. Moved your thread into CodeIgniter 4 Support.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.