简体   繁体   English

Excel PHP - PHPExcel错误

[英]Excel PHP - PHPExcel error

I'm trying to read excel file. 我正在尝试阅读excel文件。 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

I autoload the "phpoffice/phpexcel" with composer. 我用作曲家自动加载“phpoffice / phpexcel”。 Make sure you get the same to your directory. 确保您的目录相同。 If you do not use composer then point to the right directory. 如果您不使用composer,则指向正确的目录。 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());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM