How to edit existing .xls Excel file using PHP - php

I am trying to edit my existing .xls Excel file. But i can't find the proper way to edit existing .xls excel file.
I had used PHPEXCEL for reading the .xls file and then writing the .xls file. But in that I lost some excel functionality like 'macro', 'vb form' from existing .xls file.
In my case, I need to update my Excel file day by day. So currently I am using PHPEXCEL, first I need to read Excel then write it with a new record.
So I am finding the way to edit existing .xls file with my new record.
Please share your idea if you find.

If you need support for macros and forms, then you're pretty limited in your choices. There's only 3 options available:
Ilia Alshanetsky's Excel extension now on github (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/Libre Office installed on the server with Java support enabled)

Related

Ubuntu Apache PHP - Create and write to an Excel Document

I have heard of PHP Excel inorder to work with excel documents in PHP. However do I require MS Office on the Ubuntu System inorder to work and serve excel documents? Or can the PHP Excel extension work ad hoc with serving excel documents in any system?
PHPExcel is pure PHP, it has no requirement to access MS Office in any way
From the readme of the PHPExcel repo on github
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.
Requirements
PHP version 5.2.0 or higher
PHP extension php_zip enabled (required if you need PHPExcel to handle .xlsx .ods or .gnumeric files)
PHP extension php_xml enabled
PHP extension php_gd2 enabled (optional, but required for exact column width autocalculation)

How to fill data to template excel by php without api

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 :)
Old xls files were proprietary binary file formats, quite complicated, also known as Excel BIFF, you can find
reverse engineered specification here: http://www.openoffice.org/sc/excelfileformat.pdf
Microsoft's public specification here: [MS-XLS]: Excel Binary File Format (.xls) Structure (PDF) and here: [MS-XLS]: Excel Binary File Format (.xls) Structure (HTML)
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
MSDN: Office → Dev Center → Open XML SDK → Understanding the Open XML file formats
and from Ecma International → Ecma Office Open XML File Formats Standard
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
a PHP functions for copying files
a PHP functions to work with zip files
and a PHP functions to work with xml files
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

Alternative for PHP_excel

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 php tag
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
php-spreadsheetreader reads a variety of formats (.xls, .ods and .csv)
PHP-ExcelReader (xls only)
PHP_Excel_Reader (xls only)
PHP_Excel_Reader2 (xls only)
XLS File Reader Commercial and xls only
SimpleXLSX From the description it reads xlsx files , though the author constantly refers to xls
PHP Excel Explorer Commercial and xls 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)
Nuovo's spreadsheet-reader (csv, xls, xlsx, and ods)
SimpleExcel Claims to read and write Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats
PHPExcleReader Is just a ZIP with an old version of PHPExcel
Akeneo Labs Spreadsheet Parser OfficeOpenXML (.xlsx) and CSV files
spout OfficeOpenXML (xlsx) and CSV
xhook's php-spreadsheetreader Claims to do most formats
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.
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

writing to a XLS file using PHP

My application generates some .xls files and until now I was using PHPExcel lib. One of the SO has recommend me to use this approach. The problem is that I have to use some .xls templates and to append some data to them.
Who can help me with some pointers. I don't get how xlsBOF() and xlsEOF() works or have to work in my case.
If the approach you use right now works for you, don't bother with anything else.
PHPExcel writes XML files (or more accurately zip files containing XML files), in the new Excel 2007 format. For this reason, it's not compatible with older office versions (unless you install the compatibility plugin in the older office).
What this code does is write a binary XLS file in Excel 97 (BIFF8) format. It's a bit of a hack though. This won't deal correctly with unicode issues and so on. xlsBOF writes the binary header of the XLS file, and xlsEOF the footer.
If you want to write binary XLS files, you're better off using PEAR Excel Writer. I have mixed experiences with that. It gets the job done, but to use it with unicode you have to look through the bug list for a few patches that fix BIFF8 format bugs (the package is poorly maintained). It's still better than the code you linked to though.
Update: PHPExcel supports export as Excel 97 also. I remember that it used to be limited to the office 2007 file format, but apparently currently it's not. So I would recommend using PHPExcel.

How to insert/embed images in dynamically generated MS Excel file using PHP?

I need to export a report to Excel file using PHP i.e. on the fly. I am actually getting data from MySQL and presenting it in HTML tables.
I am able to export all this data into Excel file format, except images. I can't point the image source to an absolute URL, because this file also needs to work off-line.
Is there any way I can embed/insert images into this Excel file without using any library i.e. only PHP code or library which doesn't require PEAR/PECL extensions. I am using LAMP stack, so COM is not an option.
I'm not sure what your reasoning is for not using PEAR, but there is a modified version (PHP Excel Creator library) of PEAR Spreadsheet Excel Writer which does not have any dependencies on the rest of PEAR.
I know that the original PEAR version has a method Worksheet::insertBitmap() . You would need to convert the images to bitmap if they aren't already (maybe using GD
in PHP)
If you are on Windows and have decent access to the server you could also try using COM to talk to Excel and generate the file that way.

Categories