2014-05-20 2 views
2

я использую PHPExcel и у меня есть проблема: при создании объекта для чтения я получаю эту ошибку:PHPExcel: «PHPExcel_Reader_excel.php» не найден

Фатальная ошибка: Class «PHPExcel_Reader_excel.php» не найден в C : \ XAMPP \ HTDOCS \ PHPExcel \ Classes \ 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)

что не так? документация - это бит-бит, путающий

ответ

4

Если вы не добавили пользовательский читатель под названием PHPExcel_Reader_excel.php, тогда это вернет ошибку.

Как описано в разделе 1 PHPExcel User Documentation - Reading Spreadsheet Filesonline и в папке /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 ВОЛП DER показывая это использование для разных читателей, за то сам PHPExcel выбрать правильный читателя с помощью load(), а также для проверки того, что ваш файл имеет правильный формат перед установкой читателя с использованием метода identify()

я должен признаться, я бы подумал, что эта документация была довольно проста, особенно с примерами, которые включены

+0

спасибо, извините за мой глупый вопрос, я не знаю, почему я запутался в этих методах, на самом деле я был tryint createReader ("excel.xls"), но я совершил ошибку при наборе кода, но load() работает отлично ... спасибо – user2961204

0

Чтобы было проще использовать $ objReader = PHPExcel_IOFactory :: createReaderForFile ($ file); и он автоматически выберет читателя для вашего файла

Смежные вопросы