1

I'm trying to read excel file. but it's showing me error. I tried with this.

set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

// Set the Excel file name and path
$inputFileName = 'uploads/aaa.xlsx'; // this is 2007 new format.

//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}

But this error is showing...

Fatal error: Class 'PHPExcel' not found in F:\xampp\htdocs\preme\PHPExcel\Reader\Excel2007.php on line 351
Jaber
  • 277
  • 2
  • 10
  • 30

1 Answers1

0

I autoload the "phpoffice/phpexcel" with composer. Make sure you get the same to your directory. If you do not use composer then point to the right directory. Just for demonstration I pointed to the folder down below

<?php
//require_once 'vendor/autoload.php';
require_once 'vendor\phpoffice\phpexcel\Classes\PHPExcel\IOFactory.php';

$inputFileName = 'uploads/aaa.xlsx'; 

//  Read your Excel workbook
try {
  $excelReader = PHPExcel_IOFactory::createReaderForFile($inputFileName);
    $excelReader->setReadDataOnly();
    $excelReader->setLoadAllSheets();
    $excelObj = $excelReader->load($inputFileName);
    //var_dump($excelObj);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
R Alex
  • 1
  • 2