Ubuntu Apache PHP - Create and write to an Excel Document - php

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)

Related

Does PHPWord support .dot extension?

I'm importing a file with .dot extension but I get a error:
ZipArchive::locateName(): Invalid or uninitialized Zip object
The weird thing is that a .dotx file does work. Is .dot not supported anymore?
From its README.md:
The current version of PHPWord supports Microsoft Office Open XML (OOXML or OpenXML), OASIS Open Document Format for Office Applications (OpenDocument or ODF), Rich Text Format (RTF), HTML, and PDF.
Office Open XML is the newer Microsoft Office file format consisting of a zip archive containing several other files. .dotx files are Office Open XML files.
In contrast, .dot files are not zip archives. They're for legacy versions of Microsoft Office.
Office Open XML is an open specification, making it much easier to use than legacy Office formats by third-party applications. This is probably one of the reasons that PHPWord supports it but doesn't support legacy file types.
I suggest saving your .dot file as a .dotx file in a modern version of Word and then working with the .dotx version of the file in your PHP code.

PHPExcel - locking the file being viewed

I have an excel report which need to be locked from viewing without password authentication. I have tried with following snippets but it's only making it write protect. following is the code snippets I used.
$phpExcelObject->getSecurity()->setLockWindows(true);
$phpExcelObject->getSecurity()->setLockStructure(true);
$phpExcelObject->getSecurity()->setWorkbookPassword("password");
I am using PHPExcel version 1.8.
Seems like this is a know issue with PHPExcel
https://github.com/PHPOffice/PHPExcel/issues/442
Is there any alternative library for this which I can use to make my report password protected?
Thanks.
This isn't an option that PHPExcel supports. If you want to lock a file for reading, then you're very limited in your alternatives. The only libraries that I'm aware of capable of preventing read access to a file without a password are PHP's COM extension, which requires a COM enabled spreadsheet program such as MS Excel or OpenOffice Calc running on the server; the Open Office alternative to COM (PUNO), which requires Open Office installed on the server with Java support enabled; and Ilia Alshanetsky's Excel extension from github, that requires the commercial libXL component installed on your server.

How to edit existing .xls Excel file using 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)

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

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