Displaying Excel document inside browser

May 30, 2012 at 3:55 PM
Edited May 30, 2012 at 3:58 PM

First, thank you all for your development time on PHPExcel, it is exceptionally powerful.

 

I have never before needed to use it to render an already existing Excel document inside of a webbrowser, but I find myself needing to use it for that purpose now.

I had assumed that this functionality was already existing inside of the PHPExcel classes, but all I see referenced about this ability inside of the developer documentation is:

 

" Spreadsheet in memory

PHPExcel’s architecture is built in a way that it can serve as an in-memory spreadsheet. This means that, if one would want to create a web based view of a spreadsheet which communicates with PHPExcel’s object model, he would only have to write the front-end code.

Just like desktop spreadsheet software, PHPExcel represents a spreadsheet containing one or more worksheets, which contain cells with data, formulas, images, …"

 

Am I correct in assuming that this means I am going to have to recreate the entire layout of the existing Excel file, by hand, using something like table rows and columns or am I missing some nifty PHP function in the PHPExcel api that loops through the data in the excel file and attempts to display it accurately for you in the browser?

 

Thanks ahead of time~

Coordinator
May 30, 2012 at 8:48 PM

PHPExcel is a library allowing PHP to interact with the PHPExcel object, and providing file read/write capabilities; not a front-end browser or GUI application. It isn't Google Docs. You would need to write this part yourself.

You can generate HTML from an Excel workbook using the HTML Writer, but this is static HTML rather than an interactive editing application.

This would be possible by creating a custom HTML Writer (which could be based on the existing HTML Writer) that defined each table cell from your "template" workbook as a form field; then writing a back-end application which could read the data from that form, reload the file and update the PHPExcel object with new values from the form, then save it back to disk. It's easy enough if you don't allow the "structure" of the original "template" to be changed, but if you want to allow front-end users to do cell merges or similar it becomes quite complex.

You'd also need a whole host of javascript if you wanted to allow user-styling of options like cell/colum/row formatting.

I did do this at one point, using Ajax calls to handle cell updates to a persistent PHPExcel object, and responding with any cell differences that this triggered as a result of any formulae... it required building an additional network map of which cells triggered updates on what other cells, plus all the daemon logic for maintaining the PHPExcel object as a persitent object rather than reloading it onevery ajax call; and while performance was adequate running it on localhost, it slowed noticeably when run over a network (despite the persistent PHPExcel object).

 

May 30, 2012 at 10:49 PM

Thank you MarkBaker, it all makes sense in my head now.