1

I have some problem using phpexcel api.

this api is taking to long to fill data to exist template excel.

so, I want to write by pure php without using any api.

I want to know how to fill data to template excel by pure php.

Please give me some advise. Thanks :)

pnuts
  • 58,317
  • 11
  • 87
  • 139
  • good luck with that. Excel .xls is a hideously complicated format that mere mortals cannot hope to comprehend. .xslx only slightly less so. Either use an API, or don't generate native excel. Write html, write csv, something ELSE that excel can import. – Marc B Jul 14 '14 at 16:41
  • if you know any api other than phpexcel, please share me. Thanks :) – user3678411 Jul 14 '14 at 16:45
  • 1
    Note that PHPExcel __is__ "pure PHP". There's plenty of other libraries in [this list](http://stackoverflow.com/questions/3930975/alternative-for-php-excel/3931142#3931142); but if you want to do this without using a library, then I wish you the best of luck in writing it – Mark Baker Jul 14 '14 at 16:50
  • Does it mean that you want to export your database to .xls? – Mawia HL Jul 14 '14 at 16:52
  • @MawiaHL - I'm guessing that OP wants to load and populate an excel template before saving it, whether populating it from a database, or user input form data, or whatever - that effectively means both Excel read and write – Mark Baker Jul 14 '14 at 18:02
  • Hi, Mawia Hl, I want to fill data to a template excel with data from uploaded excel. if u know any other api, please share me Thanks. :) – user3678411 Jul 15 '14 at 03:28
  • @user3678411 - I've already shared the most comprehensive list of libraries for reading and writing Excel files that exists anywhere on the Internet: if your data comes from an existing spreadsheet, and your template is an existing spreadsheet and you need to save the resulting file, then your options are limited to four possibles - COM with MS Excel itself, PUNO with OpenOffice, Ilia's library (where you'll need to pay for the commercial LibXL), and PHPExcel; with the only remaining option being to write your own – Mark Baker Jul 15 '14 at 07:02
  • 1
    While PHPExcel isn't famous for its speed or memory usage, have you considered the possibility that the code you wrote to use PHPExcel for reading the data and populating the template might also be inefficient and possible to optimise? – Mark Baker Jul 15 '14 at 07:08

1 Answers1

1

Old xls files were proprietary binary file formats, quite complicated, also known as Excel BIFF, you can find

New xlsx files are "standardized" open formats. It is basically a zip file (rename it to *.zip and extract) with few xml files inside

Some general information is available at http://en.wikipedia.org/wiki/Office_Open_XML

More detailed documentation is available from

Still even the new file format is quite complicated if you want to be able to do everything or anything. In that case reusing several man/years of development effort (including debugging) materialized in a form of an existing PHP library as suggested by @mark-baker is reasonable

If you just need to do a specific task, e.g. populate existing xlsx template file with some data then you only need

  1. a PHP functions for copying files
  2. a PHP functions to work with zip files
  3. and a PHP functions to work with xml files
  4. and the documentation (from the links above) or an executable documentation in a form of Excel.exe

EDIT better links to the specification both for the old and for the new Excel file formats were provided by Mark Baker

xmojmr
  • 8,073
  • 5
  • 31
  • 54
  • 1
    It's a common misconception that you don't need to look at the OpenOffice reversed specification for BIFF files; Microsoft have it fully and ___publicly___ documented 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). – Mark Baker Jul 15 '14 at 07:01
  • 1
    Full specification for the OfficeOpenXML format can be found at http://www.ecma-international.org/news/TC45_current_work/TC45_available_docs.htm – Mark Baker Jul 15 '14 at 07:07
  • @MarkBaker I remember days **before** Microsoft documented the BIFF and **before** OpenOffice documented it sufficiently and I had to guess meaning of magic binary consts myself, it was around year 2000 so I don't know what kind of misconception did you mean. Your links are very good. Can you embed them directly (I agree) to the answer or I have to edit it myself? – xmojmr Jul 15 '14 at 08:08
  • The misconception is that the structure for BIFF format files has never been made public... a lot of people still believe that MS keep it a secret to prevent people from developing their own tools to work with MS Office files, which hasn't been the case for over 10 years – Mark Baker Jul 15 '14 at 08:29
  • @MarkBaker I see. The documents you link are dated "06/27/2008 - First Release" so 6 years ago it was still Microsoft's proprietary secret. Anyway binary Excel format is(was?) a nightmare to work with without an API (PO's question). Binary formats were deprecated, obsoleted in favor of xml-based formats by Microsoft e.g. in [Introducing the Office (2007) Open XML File Formats](http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx#office2007aboutnewfileformat_introduction) - an answer usable for PO – xmojmr Jul 15 '14 at 08:56