php PHPExcel 和 PhpSpreadsheet 之间的主要区别是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41117762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:19:41  来源:igfitidea点击:

What are the main differences between PHPExcel and PhpSpreadsheet?

phpphpexcelphpofficephpspreadsheet

提问by simhumileco

In project of PHPOfficethere are two projects associated with spreadsheet file formats:

PHPOffice 的项目中,有两个与电子表格文件格式相关的项目:

PHPExcel

PHPExcel

PHPExcel is a library written in pure PHP and providing a set of classes that allow you to write to and read from different spreadsheet file formats, like Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML, ... This project is built around Microsoft's OpenXML standard and PHP.

PHPExcel 是一个用纯 PHP 编写的库,并提供一组类,允许您写入和读取不同的电子表格文件格式,如 Excel (BIFF) .xls、Excel 2007 (OfficeOpenXML) .xlsx、CSV、Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML, ... 这个项目是围绕微软的 OpenXML 标准和 PHP 构建的。

and

PhpSpreadsheets

Php电子表格

PhpSpreadsheet is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.

PhpSpreadsheet 是一个用纯 PHP 编写的库,并提供一组类,允许您读取和写入不同的电子表格文件格式,如 Excel 和 LibreOffice Calc。

What are the main differences between them?

它们之间的主要区别是什么?

回答by Mark Baker

PHPExcel has been maintained as a library for working with spreadsheet files for many years now, and has been shackled by retaining support for older versions of PHP (>= 5.2) making it very difficult to move forward and improve it. It is a stable library, but will not be developed any further.

PHPExcel 多年来一直作为用于处理电子表格文件的库进行维护,并且由于保留对旧版本 PHP (>= 5.2) 的支持而受到束缚,因此很难向前推进和改进它。它是一个稳定的库,但不会进一步开发。

PHPSpreadsheet is the newest version of PHPExcel, and large parts of it have been rewritten to take advantage of the newer features of PHP. While retaining all the functionality of PHPExcel, it requires a minimum PHP version of 5.5 (and soon that will be dropped to require a minimum of 5.6).

PHPSpreadsheet 是 PHPExcel 的最新版本,其中大部分内容已被重写以利用 PHP 的新功能。在保留 PHPExcel 的所有功能的同时,它要求最低 PHP 版本为 5.5(很快将被删除到最低要求为 5.6)。

The change in library name was to reflect the fact that it isn't limited to Excel spreadsheets; but supports a wider range of spreadsheet file formats.

库名称的更改是为了反映它不仅限于 Excel 电子表格的事实;但支持更广泛的电子表格文件格式。

EDIT 2020:

编辑 2020:

PHP Excel was officially deprecated in 2017 and permanently archived in 2019.

PHP Excel 于 2017 年正式弃用,并于 2019 年永久存档。

PHP Excel has not be maintained for years and must not be used anymore. All users must migrate to its direct successor PhpSpreadsheet, or anotheralternative.

PHP Excel 已多年未维护,不得再使用。所有用户都必须迁移到其直接继承者 PhpSpreadsheet 或其他替代方案。

回答by cssyphus

Further to Mark Baker'sanswer above, there are numerous architectural and syntactical changes to how the new PhpSpreadsheet library is used.

除了上面Mark Ba​​ker 的回答之外,新的 PhpSpreadsheet 库的使用方式有许多架构和语法上的变化。

First, note that there is an included migration tool that performs many of thePhpExcel -to- PhpSpreadsheetsyntactical changes for you.

首先,请注意,有一个包含的迁移工具可以为您执行许多从PhpExcel 到 PhpSpreadsheet 的语法更改。

 

Non-Exhaustive Summary Of Changes:

变更的非详尽总结:

(1) Most Important Change: PhpSpreadsheet relies upon Composerbeing installed.

(1) 最重要的变化:PhpSpreadsheet 依赖于安装的Composer

Strongly inspired by node's npm and ruby's bundler, Composer is not a package manager in the same sense as Yum or Apt. Although it does deal with "packages" and/or libraries, it is a more pure dependency manager, as it manages dependencies on a per-project basis, installing them in a directory (usually named "vendor") inside your project. By default, it does not install anything globally. (It does however support a "global" project for convenience via the global command.)

受到 node 的 npm 和 ruby​​ 打包器的强烈启发,Composer 不是与 Yum 或 Apt 相同意义上的包管理器。尽管它确实处理“包”和/或库,但它是一个更纯粹的依赖项管理器,因为它基于每个项目管理依赖项,将它们安装在项目内的目录(通常称为“供应商”)中。默认情况下,它不会全局安装任何东西。(但是,为了方便起见,它确实通过 global 命令支持“全局”项目。)

It is possible to use PhpSpreadsheet without Composer, and here are some thoughts on how to do that. Here are more thoughts direct from the mavenson this same topic.

可以在没有 Composer 的情况下使用 PhpSpreadsheet,这里有一些关于如何做到这一点的想法。这里有更多来自专家们关于同一主题的直接想法

FWIW, I opened a ticket with my webhostand in 10 minutes received a reply that Composer had been installed on our shared hosting (Green plan, for those wondering). Not saying you will have the same good luck, but perhaps the anecdotal info will be helpful. Worth giving a try with your webhost.

FWIW,我向我的虚拟主机开了一张票并在 10 分钟内收到答复,说 Composer 已安装在我们的共享主机上(绿色计划,对于那些想知道的人)。并不是说你会有同样的好运,但也许轶事信息会有所帮助。值得尝试与您的虚拟主机。

(2) Namespaces were introduced

(2)引入命名空间

The code side of PhpSpreadsheet has evolved since PhpExcel as well. Whereas the entry point class of PhpExcel - Classes/PHPExcel.php - reflected its namesake, PhpSpreadsheet includes the autoload.php file in the root of the vendor directory. It also utilizes some namespaces to simplify coding:

PhpSpreadsheet 的代码方面也从 PhpExcel 开始发展。虽然 PhpExcel 的入口点类 - Classes/PHPExcel.php - 反映了它的同名,但 PhpSpreadsheet 在供应商目录的根目录中包含 autoload.php 文件。它还利用一些命名空间来简化编码:

<?php
   use PhpOffice\PhpSpreadsheet\IOFactory;
   use PhpOffice\PhpSpreadsheet\Spreadsheet;
   require_once 'vendor/autoload.php';

(3) Readers and writers were renamed

(3) Readers 和 writers 更名

(4) Reader/Writer short names were changed, significantly. For example:

(4) Reader/Writer 短名称已显着更改。例如:

'Excel2003XML' ==> 'Xml' *the leading capital letter is mandatory !*
'Excel2007'    ==> 'Xlsx'
'Excel5'       ==> 'Xls'
'HTML'         ==> 'Html'
'CSV'          ==> 'Csv'   etc.

Did you make note that the first letter is capitalized? Required.

你有没有注意到第一个字母是大写的?必需的。

(5) IOFactory methods were simplified:

(5) IOFactory 方法被简化:

PHPExcel_IOFactory::getSearchLocations()  ==> replaced by ==>  IOFactory::registerReader()
PHPExcel_IOFactory::setSearchLocations()  ==> replaced by ==>  IOFactory::registerWriter()
PHPExcel_IOFactory::addSearchLocation()

For example,

例如,

\PHPExcel_IOFactory::addSearchLocation($type, $location, $classname);   <=== PhpExcel

\PhpOffice\PhpSpreadsheet\IOFactory::registerReader($type, $classname); <=== PhpSpreadsheet

(6) Other Changes/Deprecations:

(6)其他更改/弃用:

Worksheet::duplicateStyleArray()
DataType::dataTypeForValue()
Conditional::get/setCondition()
Worksheet::get/setDefaultStyle()
Worksheet::get/setSelectedCell()
Writer\Xls::setTempDir() <==== functionality dropped

(7) The class PHPExcel_Autoloader was removed entirely and is replaced by composer autoloading mechanism.

(7) PHPExcel_Autoloader 类被完全删除,并由 composer 自动加载机制取代。

(8) PDF libraries must be installed via composer. The PHPExcel_Settings::get/setPdfRenderer()methods were removed and are replaced by IOFactory::registerWriter() instead.

(8) PDF 库必须通过composer 安装。这些PHPExcel_Settings::get/setPdfRenderer()方法已被删除,并由 IOFactory::registerWriter() 代替。

(9) When rendering charts for HTML or PDF outputs, the process was also simplified. And while JpGraph support is still available, it is unfortunately not up to date for latest PHP versions and it will generate various warnings.

(9) 在为 HTML 或 PDF 输出呈现图表时,过程也得到了简化。虽然 JpGraph 支持仍然可用,但遗憾的是它不是最新的 PHP 版本,它会生成各种警告。

(10) Support for PclZip were dropped in favor of the more complete and modern PHP extension ZipArchive. So many changes to those classes.

(10) 不再支持 PclZip,取而代之的是更完整和现代的 PHP 扩展 ZipArchive。这些课程有很多变化。

(11) Cell caching was heavily refactored to leverage PSR-16. That means most classes related to that feature were removed.

(11) 对单元缓存进行了大量重构以利用 PSR-16。这意味着与该功能相关的大多数类都被删除了。

(12) Array keys used for styling have been standardized for a more coherent experience. It now uses the same wording and casing as the getter and setter

(12) 用于样式的数组键已标准化,以获得更连贯的体验。它现在使用与 getter 和 setter 相同的措辞和大小写

(13) Methods to manipulate coordinates in PHPExcel_Cellwere extracted to a dedicated new class \PhpOffice\PhpSpreadsheet\Cell\Coordinate. The methods include:

(13) 操作坐标的方法PHPExcel_Cell被提取到一个专门的新类中\PhpOffice\PhpSpreadsheet\Cell\Coordinate。方法包括:

absoluteCoordinate()
absoluteReference()
columnIndexFromString()
coordinateFromString()
buildRange()
... and half-a-dozen more ...

(14) Column indexes are now based on 1. So column A is the index 1. This is consistent with rows starting at 1 and Excel function COLUMN() that returns 1 for column A.

(14) 列索引现在基于 1。所以 A 列是索引 1。这与从 1 开始的行和 Excel 函数 COLUMN() 为列 A 返回 1 一致。

(15) Default values for many methods were removed when it did not make sense. Typically, setter methods should not have default values.

(15) 许多方法的默认值在没有意义时被删除。通常,setter 方法不应具有默认值。

(16) Dropped conditionally returned cell... It is no longer possible to change the type of returned value. It always returns the Worksheet and never the Cell or Rule, in methods such as: Worksheet::setCellValue(), Worksheet::setCellValueExplicit(), etc. For e.g.:

(16) 丢弃有条件返回的单元格... 无法再更改返回值的类型。它总是返回工作表,从不细胞或规则,在方法,如:Worksheet::setCellValue()Worksheet::setCellValueExplicit()等等。例如:

$cell = $worksheet->setCellValue('A1', 'value', true);  <==== PhpExcel

$cell = $worksheet->getCell('A1')->setValue('value');   <==== PhpSpreadsheet

For additional details on these changes, refer to the source document, below.

有关这些更改的更多详细信息,请参阅下面的源文档。

References:

参考:

PhpSpreadsheet Docs - Migration From PhpExcel- readthedocs.io

PhpSpreadsheet Docs - 从 PhpExcel 迁移- readthedocs.io

Making the switch from PhpExcel to PhpSpreadsheetby Rob Gravelle of Ottawa

渥太华的 Rob Gravelle从 PhpExcel 切换到 PhpSpreadsheet