- Обзор PHP расширений для чтения файлов Excel
- PHPExcel
- Пример чтения файла в массив:
- SimpleXLSX
- PHP-ExcelReader
- PHP-Excel-Reader
- Nuovo Spreadsheet-Reader
- PHP-Spreadsheetreader
- Saved searches
- Use saved searches to filter your results more quickly
- License
- AsperaGmbH/xlsx-reader
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Обзор PHP расширений для чтения файлов Excel
В статье представлены различные PHP-расширения для чтения файлов XLS, XLSX, описаны их плюсы и минусы, а также примеры чтения.
PHPExcel
Огромная библиотека читает и формирует фалы xls, xlsx, csv.
Пример чтения файла в массив:
require_once __DIR__ . '/PHPExcel-1.8/Classes/PHPExcel/IOFactory.php'; // Файл xlsx $xls = PHPExcel_IOFactory::load(__DIR__ . '/test.xlsx'); // Первый лист $xls->setActiveSheetIndex(0); $sheet = $xls->getActiveSheet(); foreach ($sheet->toArray() as $row)
SimpleXLSX
- Менее прожорлив к памяти.
- Не всегда может прочитать файл, например файл сформированный PHPExcel.
require_once __DIR__ . '/simple-xlsx/simplexlsx.class.php'; // Файл xlsx $xlsx = new SimpleXLSX(__DIR__ . '/test.xlsx'); // Первый лист $sheet = $xlsx->rows(1); foreach ($sheet as $row)
PHP-ExcelReader
require_once __DIR__ . '/phpExcelReader/Excel/reader.php'; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF-8'); // Файл xls $data->read(__DIR__ . '/test.xls'); // Первый лист $sheet = $data->sheets[0]['cells']; foreach ($sheet as $row)
PHP-Excel-Reader
Форк библиотеки «PHP Excel Reader» с SourceForge предназначенный для вывода таблицы в HTML.
Например файл example.xls выведет следующим образом:
table.excel < border: 1px solid #CCCCCC; border-collapse:collapse; font-family:sans-serif; font-size:12px; margin: 0 auto; >table.excel thead th, table.excel tbody th < border: 1px solid #CCCCCC; text-align: center; vertical-align:bottom; >table.excel tbody th < text-align:center; width:20px; >table.excel tbody td < vertical-align:bottom; >table.excel tbody td dump(true, true); ?>
Также у библиотеки есть методы для получения формата и содержания каждой ячейки по отдельности.
Nuovo Spreadsheet-Reader
Читает файлы XLSX, XLS, CSV и OpenOffice ods. Для чтения XLS используется предыдущая библиотека php-excel-reader.
require_once __DIR__ . '/spreadsheet-reader/php-excel-reader/excel_reader2.php'; require_once __DIR__ . '/spreadsheet-reader/SpreadsheetReader.php'; // Файл xlsx, xls, csv, ods. $Reader = new SpreadsheetReader(__DIR__ . '/test.xlsx'); // Номер листа. $Reader -> ChangeSheet(0); foreach ($Reader as $Row)
PHP-Spreadsheetreader
Откроет только файлы в формате XML Excel 2004.
$file = __DIR__ . '/test.xml'; require_once __DIR__ . '/SpreadsheetReader/SpreadsheetReader.php'; $reader = new SpreadsheetReader; // Файл xml $sheets = $reader->read(__DIR__ . '/test.xml'); // Выводим Первый лист foreach ($sheets[0] as $row)
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
xlsx-reader is a PHP library for fast and efficient reading of XLSX spreadsheet files. Its focus is on reading the data contained within XLSX files, disregarding all document styling beyond that which is strictly necessary for data type recognition. It is built to be usable for very big XLSX files in the magnitude of multiple GBs.
License
AsperaGmbH/xlsx-reader
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
xlsx-reader is an extension of the XLSX-targeted spreadsheet reader that is part of spreadsheet-reader.
It delivers functionality to efficiently read in data contained within the given XLSX file.
The focus of this library is on delivering data contained in XLSX spreadsheet cells, not the document’s styling. As such, the library offers no support for XLSX capabilities that aren’t strictly necessary to achieve this goal. Only basic cell value formatting and shared string functionalities are supported.
- PHP 7.1.0 or newer, with at least the following optional features enabled:
- Zip (see http://php.net/manual/en/zip.installation.php)
- XMLReader (see http://php.net/manual/en/xmlreader.installation.php)
Installation using Composer
The package is available on Packagist. You can install it using Composer.
composer require aspera/xlsx-reader
All data is read from the file sequentially, with each row being returned as an array of columns.
use Aspera\Spreadsheet\XLSX\Reader; $reader = new Reader(); $reader->open('example.xlsx'); foreach ($reader as $row) < print_r($row); > $reader->close();
XLSX files with multiple worksheets are also supported. The method getSheets() returns an array with sheet indexes as keys and Worksheet objects as values. The method changeSheet($index) is used to switch between sheets to read.
use Aspera\Spreadsheet\XLSX\Reader; $reader = new Reader(); $reader->open('example.xlsx'); $sheets = $reader->getSheets(); foreach ($sheets as $index => $sheet_data) < $reader->changeSheet($index); echo 'Sheet #' . $index . ': ' . $sheet_data->getName(); // Note: Any call to changeSheet() resets the current read position to the beginning of the selected sheet. foreach ($reader as $row_number => $row) < echo 'Row #' . $row_number . ': ' . print_r($row, true); > > $reader->close();
Options to tune the reader’s behavior and output can be specified via a ReaderConfiguration instance.
For a full list of supported options and their effects, consult the in-code documentation of ReaderConfiguration.
use Aspera\Spreadsheet\XLSX\Reader; use Aspera\Spreadsheet\XLSX\ReaderConfiguration; use Aspera\Spreadsheet\XLSX\ReaderSkipConfiguration; $reader_configuration = (new ReaderConfiguration()) ->setTempDir('C:/Temp/') ->setSkipEmptyCells(ReaderSkipConfiguration::SKIP_EMPTY) ->setReturnDateTimeObjects(true) ->setCustomFormats(array(20 => 'hh:mm')); // For a full list of supported options and their effects, consult the in-code documentation of ReaderConfiguration. $spreadsheet = new Reader($reader_configuration);
Notes about library performance
XLSX files use so-called «shared strings» to optimize file sizes for cases where the same string is repeated multiple times. For larger documents, this list of shared strings can become quite large, causing either performance bottlenecks or high memory consumption when parsing the document.
To deal with this, the reader selects sensible defaults for maximum RAM consumption. Once this memory limit has been exhausted, the file system is used for further optimization strategies.
To configure this behavior in detail, e.g. to increase the amount of memory available to the reader, a SharedStringsConfiguration instance can be attached to the ReaderConfiguration instance supplied to the reader’s constructor.
For a full list of supported options and their effects, consult the in-code documentation of SharedStringsConfiguration.
use Aspera\Spreadsheet\XLSX\Reader; use Aspera\Spreadsheet\XLSX\ReaderConfiguration; use Aspera\Spreadsheet\XLSX\SharedStringsConfiguration; $shared_strings_configuration = (new SharedStringsConfiguration()) ->setCacheSizeKilobyte(16 * 1024) ->setUseOptimizedFiles(false); // For a full list of supported options and their effects, consult the in-code documentation of SharedStringsConfiguration. $reader_configuration = (new ReaderConfiguration()) ->setSharedStringsConfiguration($shared_strings_configuration); $spreadsheet = new Reader($reader_configuration);
Notes about unsupported features
This reader’s purpose is to allow reading of basic data (text, numbers, dates. ) from XLSX documents. As such, there are no plans to extend support to include all features available for XLSX files. Only a minimal subset of XLSX capabilities is supported.
In particular, the following should be noted in regard to unsupported features:
- Display cell width is disregarded. As a result, in cases in which popular xlsx editors would shorten values using scientific notation or «#####»-placeholders, the reader will return un-shortened values instead.
- Files with multiple internal shared strings files are not supported.
- Files with multiple internal styles definition files are not supported.
- Fractions are only partially supported. The results delivered by the reader might be slightly off from the original input.
All the code in this library is licensed under the MIT license as included in the LICENSE.md file.
About
xlsx-reader is a PHP library for fast and efficient reading of XLSX spreadsheet files. Its focus is on reading the data contained within XLSX files, disregarding all document styling beyond that which is strictly necessary for data type recognition. It is built to be usable for very big XLSX files in the magnitude of multiple GBs.