2014-05-20 25 views
2

我使用phpexcel和我有一个问题:创建读者对象时,我得到这个错误:PHPExcel:“PHPExcel_Reader_excel.php”未找到

致命错误:类“PHPExcel_Reader_excel.php”未发现在C :\ XAMPP \ htdocs中\ phpexcel \类\ PHPExcel \ IOFactory.php上线170

我的代码是:

<?php 
require_once(dirname(__FILE__)."/Classes/phpexcel.php"); 
//or 
require_once(dirname(__FILE__)."/Classes/PHPExcel/IOFactory.php"); 
//$phpexcel = new PHPExcel(); 
$reader = PHPExcel_IOFactory::createReader("excel.php"); 
?> 

我检查IOFactory.php上线170,发现这一点:

$searchType = 'IReader'; 

    // Include class 
    foreach (self::$_searchLocations as $searchLocation) { 
     if ($searchLocation['type'] == $searchType) { 
      $className = str_replace('{0}', $readerType, $searchLocation['class']); 

      $instance = new $className(); 
      if ($instance !== NULL) { 
       return $instance; 
      } 
     } 
    } 

但是它不可能找到任何类,因为它们使用_而不是/(路径是phpexcel \ Classes \ PHPExcel \ Reader,并且有像excel5.php excel2007.php但不是excel.php的文件)

有什么不对?文档痘痘位,除非您已添加自己的自定义读者称为PHPExcel_Reader_excel.php那么这会返回一个错误混淆

回答

4

如在PHPExcel User Documentation - Reading Spreadsheet Filesonline第1节,并在/Documentation文件夹中所描述的,有7名不同的读者可用7种不同的电子表格格式:

PHPExcel can read a number of different spreadsheet file formats, although not all features are supported by all of the readers. Check the Functionality Cross-Reference document (Functionality Cross-Reference.xls) for a list that identifies which features are supported by which readers.

Currently, PHPExcel supports the following File Types for Reading:

Excel5

The Microsoft Excel™ Binary file format (BIFF5 and BIFF8) is a binary file format that was used by Microsoft Excel™ between versions 95 and 2003. The format is supported (to various extents) by most spreadsheet programs. BIFF files normally have an extension of .xls. Documentation describing the format can be found online at http://msdn.microsoft.com/en-us/library/cc313154(v=office.12).aspx or from http://download.microsoft.com/download/2/4/8/24862317-78F0-4C4B-B355-C7B2C1D997DB/[MS-XLS].pdf (as a downloadable PDF).

Excel2003XML

Microsoft Excel™ 2003 included options for a file format called SpreadsheetML. This file is a zipped XML document. It is not very common, but its core features are supported. Documentation for the format can be found at http://msdn.microsoft.com/en-us/library/aa140066%28office.10%29.aspx though it’s sadly rather sparse in its detail.

Excel2007

Microsoft Excel™ 2007 shipped with a new file format, namely Microsoft Office Open XML SpreadsheetML, and Excel 2010 extended this still further with its new features such as sparklines. These files typically have an extension of .xlsx. This format is based around a zipped collection of eXtensible Markup Language (XML) files. Microsoft Office Open XML SpreadsheetML is mostly standardized in ECMA 376 (http://www.ecma-international.org/news/TC45_current_work/TC45_available_docs.htm) and ISO 29500.

OOCalc

aka Open Document Format (ODF) or OASIS, this is the OpenOffice.org XML File Format for spreadsheets. It comprises a zip archive including several components all of which are text files, most of these with markup in the eXtensible Markup Language (XML). It is the standard file format for OpenOffice.org Calc and StarCalc, and files typically have an extension of .ods. The published specification for the file format is available from the OASIS Open Office XML Format Technical Committee web page (http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=office#technical). Other information is available from the OpenOffice.org XML File Format web page (http://xml.openoffice.org/general.html), part of the OpenOffice.org project.

SYLK

This is the Microsoft Multiplan Symbolic Link Interchange (SYLK) file format. Multiplan was a predecessor to Microsoft Excel™. Files normally have an extension of .slk. While not common, there are still a few applications that generate SYLK files as a cross-platform option, because (despite being limited to a single worksheet) it is a simple format to implement, and supports some basic data and cell formatting options (unlike CSV files).

Gnumeric

The Gnumeric file format is used by the Gnome Gnumeric spreadsheet application, and typically files have an extension of .gnumeric. The file contents are stored using eXtensible Markup Language (XML) markup, and the file is then compressed using the GNU project's gzip compression library. http://projects.gnome.org/gnumeric/doc/file-format-gnumeric.shtml

CSV

Comma Separated Value (CSV) file format is a common structuring strategy for text format files. In CSV flies, each line in the file represents a row of data and (within each line of the file) the different data fields (or columns) are separated from one another using a comma (“,”). If a data field contains a comma, then it should be enclosed (typically in quotation marks ("). Sometimes tabs “\t” or the pipe symbol (“|”) are used as separators instead of a comma. Because CSV is a text-only format, it doesn't support any data formatting options.

您需要通过当您使用指定的读者该方法createReader(),例如:

$reader = PHPExcel_IOFactory::createReader("Excel5"); 

有大量的实例在/Examples FOL为了让PHPExcel自己选择使用load()的正确阅读器,并且在使用identify()方法设置阅读器之前验证您的文件的格式正确

我必须承认,我会认为这是文件相当简单,特别是与包括

+0

谢谢,我很抱歉我的愚蠢问题,我不知道为什么我对这些方法感到困惑,实际上我是tryint createReader(“excel.xls” )但我输入我的代码时犯了一个错误,但load()正常工作......谢谢 – user2961204

0

为了更方便您可以使用实例 $ objReader = PHPExcel_IOFactory :: createReaderForFile($文件); 它会自动为您的文件选择一个阅读器