136

Is there any alternative for PHP_excel which can "Export to XLSX/XLS" file in a customized format?

This is a General Reference question for the tag

Community
  • 1
  • 1
sandeep
  • 2,862
  • 9
  • 44
  • 54
  • 2
    Given that the frequent questions asking for libraries that can read/write Excel files are regularly pointed to this answer because of the list provided... and that the list in question is regularly updated, I fail to appreciate why it should have been closed. – Mark Baker Sep 21 '13 at 21:01
  • 1
    I wasn't one of the closers, but the reason in the "closed as off-topic" box seems to match pretty closely to me. See als: [why shopping list questions are bad](http://meta.stackexchange.com/q/158809). I realise *your answer* is high quality and being updated, but the question itself still falls in that off-topic category. – IMSoP Sep 21 '13 at 21:16
  • 16
    **Although the question is technically off-topic, this is the canonical Q&A on this topic and offers significant value. Please refrain from closing it.** – Gordon Dec 09 '13 at 19:26

2 Answers2

293

For Writing Excel

  • PEAR's PHP_Excel_Writer (xls only)
  • php_writeexcel from Bettina Attack (xls only)
  • XLS File Generator commercial and xls only
  • Excel Writer for PHP from Sourceforge (spreadsheetML only)
  • Ilia Alshanetsky's Excel extension now on github (xls and xlsx, and requires commercial libXL component)
  • PHP's COM extension (requires a COM enabled spreadsheet program such as MS Excel or OpenOffice Calc running on the server)
  • The Open Office alternative to COM (PUNO) (requires Open Office installed on the server with Java support enabled)
  • PHP-Export-Data by Eli Dickinson (Writes SpreadsheetML - the Excel 2003 XML format, and CSV)
  • Oliver Schwarz's php-excel (SpreadsheetML)
  • Oliver Schwarz's original version of php-excel (SpreadsheetML)
  • excel_xml (SpreadsheetML, despite its name)... link reported as broken
  • The tiny-but-strong (tbs) project includes the OpenTBS tool for creating OfficeOpenXML documents (OpenDocument and OfficeOpenXML formats)
  • SimpleExcel Claims to read and write Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats
  • KoolGrid xls spreadsheets only, but also doc and pdf
  • PHP_XLSXWriter OfficeOpenXML
  • PHP_XLSXWriter_plus OfficeOpenXML, fork of PHP_XLSXWriter
  • php_writeexcel xls only (looks like it's based on PEAR SEW)
  • spout OfficeOpenXML (xlsx) and CSV
  • Slamdunk/php-excel (xls only) looks like an updated version of the old PEAR Spreadsheet Writer

For Reading Excel

A new C++ Excel extension for PHP, though you'll need to build it yourself, and the docs are pretty sparse when it comes to trying to find out what functionality (I can't even find out from the site what formats it supports, or whether it reads or writes or both.... I'm guessing both) it offers is phpexcellib from SIMITGROUP.

All claim to be faster than PHPExcel from codeplex or from github, but (with the exception of COM, PUNO Ilia's wrapper around libXl and spout) they don't offer both reading and writing, or both xls and xlsx; may no longer be supported; and (while I haven't tested Ilia's extension) only COM and PUNO offers the same degree of control over the created workbook.

nawfal
  • 70,104
  • 56
  • 326
  • 368
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • [Ilia's extension](https://github.com/iliaal/php_excel) now supports XLS and XLSX. – Sara Jan 17 '13 at 18:21
  • Note, however, that Iliaal's extension requires LibXL which is a quite costly commercial library. – pilsetnieks Mar 13 '13 at 11:37
  • @Nouveau - yeah, I think I've got libXL flagged as commercial – Mark Baker Mar 13 '13 at 11:40
  • @Mark, I've followed a bunch of other topics concerning memory limit and cache for PHPExcel. But my host is very limited. In my case scenario I don't need to manipulate data in any way, just insert straight into database. Do I really need PHPExcel or can this be acomplished with native MySQL import (.csv, .xls) functions? – rzb May 15 '13 at 21:49
  • 6
    @RZB - You use whichever library works for you, though MySQL doesn't (as far as I'm aware) have any native import function for .xls files, only for .csv using LOAD DATA INFILE. As the developer of PHPExcel, I will certainly promote it and recommend it where appropriate, but I don't enforce its use when it isn't the most appropriate option. – Mark Baker May 15 '13 at 22:10
  • 1
    @velcrow a nice lightweight engine. Good recommendation, needs some work, but outputs quality XSLX files – The Thirsty Ape Dec 24 '13 at 21:33
  • I have been given a 5lakh rows threshold that must be supported to parse an xls or xlsx reader. But it takes almost 15 minutes to read 1 lakh rows. Chunk reading in PhpExcel is not suitable as it trades off with time efficiency. So currently just loading the current sheet is my only solution. But still taking forever.. – cosmoloc May 18 '14 at 16:44
  • @var17 - While PHP isn't as fast as using COM or PUNO or Ilia's extension, it tries to be as fast as possible while using pure PHP to parse files; but that doesn't prevent users from writing scripts that are inefficient... have you profiled your script to take a look at what's actually taking all the time, because 15 minutes is a lot slower than some of my large files – Mark Baker May 18 '14 at 16:50
  • excel_xml link is broken! – dap.tci Sep 16 '14 at 12:55
  • 1
    @Mark, It would be great if you could do something like `$manyAnswers = split($libSeparator, $thisAnswer); // So we could vote and comment by lib` – dap.tci Sep 16 '14 at 13:44
  • Hey @MarkBaker, can you add [Spout](https://github.com/box/spout)? Useful for processing large files that other libraries can't process (out of memory, time limit) – Adrien Feb 21 '15 at 20:26
  • @Adrien - out of interest (without spending time delving into the code to see for myself) how does it keep memory usage low? I'm guessing it uses arrays internally rather than objects, and uses XMLReader rather than SimpleXML – Mark Baker Feb 21 '15 at 20:43
  • It uses streams and XMLReader (although it uses SimpleXML also but with small nodes, because its API is easier to use). And for reading the shared strings file, the data is split and cached to avoid having to load the entire file in memory. The drawback, compared to PHPExcel and others, is that you can't go backwards (after process row 10 and 11, you cannot change row 10 again). We can chat more about it if you'd like – Adrien Feb 21 '15 at 20:57
  • I'd be interested in a chat at some point, but only after I've had a chance to take a look at the code - I've done some work on streaming and XMLReader for PHPExcel, so I'd be interested in looking at your implementation – Mark Baker Feb 21 '15 at 21:05
  • One project that is very limited but still worth mention is [ExcelDataTables](https://github.com/eLearningAG/exceldatatables). It is the only lib I have come across which handles pivot tables (for .xlsx files). Very useful if you have pivot table template in one sheet and need to just dump data to another sheet which can act as source for pivot table. – nawfal Apr 04 '16 at 09:15
  • There is an issue with box/spout: it can not read spreadsheet files from Amazon S3 because its underlying library doesn't support stream wrappers. See: https://github.com/box/spout/issues/132 and https://github.com/box/spout/issues/176 for references. – Vasiliy Toporov Jul 28 '17 at 10:27
41

I wrote a very simple class for exporting to "Excel XML" aka SpreadsheetML. It's not quite as convenient for the end user as XSLX (depending on file extension and Excel version, they may get a warning message), but it's a lot easier to work with than XLS or XLSX.

http://github.com/elidickinson/php-export-data

Eli
  • 5,500
  • 1
  • 29
  • 27