This website uses cookies and similar technologies to understand visitors' experiences. By continuing to use this website, you accept our use of cookies and similar technologies,Terms of Use, and Privacy Policy.

May 20 2011 - 09:49 AM
Handling Excel Files In Your PHP Script
I've been recently working on a script that uploads image batches to PocketKnowledge via its backend. In addition to a deepened understanding of the application's construct and the functionality of its various modules, there were actually some good findings about spreadsheet processing that can be used in the future. The two popular formats of excel files a PHP script will need to handle are csv and xls. For the former, people can use a standard PHP utility called fgetcsv. It's easy to use in that it parses csv files like a usual file handler. For each row in the file, it returns a list of the fields. It can be configured to use different cell delimiters (comma or semicolon) and enclosures (double or single quotes). In order to handle an xls file, however, more powerful tools are needed and there are a couple of them available. If it's just about reading the file, an external class excel_reader2 will work pretty good. It can extract all the information about sheets, columns, rows and cells. In fact, it can even render a simple table on a web page based on the xls file. (more...) Finally, there's the powerful PHP extension called PHPExcel. It can process more spreadsheet formats and can carry out most of the common Excel operations. In order to use it, other extensions including php_zip, php_xml and php_gd2 must be installed first. People can choose the tool that fits their needs best in their work.
|By: Yudan Li|10401 Reads