Does anyone know how to read an excel with PhpSpreadsheet in Codeigniter?

0

I am trying to read an excel file in codeigniter to save it in a database. I was looking for a php library to work with excel and found phpExcel but when I go to the site it tells me that it is deprecated and that it is now phpspreadsheet and I can not find any example that shows how use it.

    
asked by Max LLaupi 05.01.2018 в 15:38
source

1 answer

2

Because it is a library that is widely used and constantly updated, I recommend PHPOffice / PhpSpreadsheet . Here I leave a basic script from its installation until the opening of an excel file.

For installation, just the following command:

composer require phpoffice/phpspreadsheet

This will create the vendor folder with the following structure

vendor
  |
  ├─ composer
  |
  └─ phpoffice
        |
        └─ phpspreadsheet

Once the library is installed you can open a file in Xlsx format in the following way

<?php

require 'vendor/autoload.php';
    $filename = "mi_archivo.xlsx";
    $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
    $spreadsheet = $reader->load($filename);
try {

} catch (\Exception $e) {
    echo 'Ocurrio un error al intentar abrir el archivo ' . $e;
}

There are a number of examples that you can review here I hope this gives you a light for resolve

    
answered by 27.03.2018 в 22:28