Reading excel, turning array to visible styled excel sheet

Topics: Developer Forum
Jun 17, 2012 at 2:36 AM

Hi everyone,

How would I turn this array into a styled PHPExcel sheet so I can view it on that page (under the <HR>)

https://www.thewebrary.com/presentations.php?file=493

The excel file is full of color, borders, etc to see what PHPExcel can pick up on and display. Shouldnt PHPExcel automatically pick up the styles? Why does it even bother to return it as a array? I really could use some insight because I'm lost. 

Thanks for your time,

Marc

Coordinator
Jun 17, 2012 at 10:44 AM
Edited Jun 17, 2012 at 11:09 AM

PHPExcel does pick up the styles automatically. But PHPexcel is not a solution to everything you or anybody else might want to do with Excel files... it's a toolkit that provides a comprehensive set of tools allowing you to build your own solution. It'd purpose is to abstract the complexity of the various spreadsheet file formats.

The file you're running is simply displaying the raw data as an array. Why does it return it as an array, because many people want to be able to access the data from Excel, not simply to display it on screen, but perhaps to load it into a database, or change some of the cell values, or to save it in a different format.

Load your excel file and then use the HTML Writer to generate a pretty html page of data from that workbook with all its formatting.

Jun 19, 2012 at 12:35 AM
Edited Jun 19, 2012 at 12:37 AM

Do you know of a PHP solution? Otherwise with PHPExcel could I convert the new xlsx 2007+ to old 2005 or whatever year so phpexcel 1.7.7 can read it?

Coordinator
Jun 19, 2012 at 7:44 AM

The solution is what I said: to use the appropriate Reader for your Excel file (Excel2007 or Excel5), then use the HTML Writer to render that as HTML.

Once you've included the PHPExcel library, it's basically just three lines of code:

$objPHPExcel = PHPExcel_IOFactory::load("myTestFile.xlsx");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');
Jun 19, 2012 at 8:38 PM

Wow worked like a charm!! Thanks for the help!

Also can PHPPowerpoint and/or PHPWord display files like this? Or only write them..

Coordinator
Jun 20, 2012 at 8:59 AM

At the moment PHPPowerPoint and PHPWord can only write files, and only a limited set of formats (.pptx, .odp and .docx). The intention with pulling everything under the same ownership in github is to extend reader and writer capabilities of PHPPowerPoint and PHPWord, and so that components common to the 3 office applications can be more easily shared and integrated.