CodeIgniter Forums
phpspreadsheet in Codeigniter4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: phpspreadsheet in Codeigniter4 (/showthread.php?tid=77353)



phpspreadsheet in Codeigniter4 - kabata+ - 08-20-2020

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');

[font=Tahoma, Verdana, Arial, sans-serif][font=Tahoma, Verdana, Arial, sans-serif]r[/font][font=Tahoma, Verdana, Arial, sans-serif]eq[/font][font=Tahoma, Verdana, Arial, sans-serif]uire(vendor/autoload.php): failed to open stream: No such file or directory [/font][/font]


[font=Tahoma, Verdana, Arial, sans-serif]I need a help on how to set it up and use it in my app.[/font]


RE: phpspreadsheet in Codeigniter4 - jreklund - 08-20-2020

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.