Is there a function...?

Feb 10, 2010 at 8:53 AM

Hey guys,

Im a web developer, but what i am looking for is a program that can read xlsx files, and output them to the browser.

I know this class can CREATE those files ( from the documentation ) but can it also import them to php and then output them as data to the browser? with say an echo function or something like that?

I tried phpexcelreader but that script did not work....looking forward to an answer.


Thank you.

Feb 10, 2010 at 11:31 AM

Perfectly easy. Read the workbook using the Excel2007 Reader (or let the IO Factory detect that it's an Excel 2007 file) then save (to php://output) using the HTML Writer

require_once 'PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("myWorkBook.xlsx");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');

Feb 10, 2010 at 8:42 PM

Hmmm, so that directly outputs the spreadsheet to the browser.

something like this

$foo =  $objWriter->save(str_replace("php://output");

Would be invalid then?

I need to be able to display it within the current template. Sorry, there was just a lot of documentation and i couldnt find something regarding this.


Thanks again for your help!

Feb 10, 2010 at 9:28 PM

$foo =  $objWriter->save("php://output");

is perfectly valid PHP, but the save method has no return so $foo would be assigned a value of null. php://output is a standard php output stream. The save() method doesn't assign the data to $foo, but saves to the specified output stream, in this case php://output. Equally, you could specify a filename here:

$foo =  $objWriter->save("filename.html")

To display within the current template, you could save to file, then use standard PHP file_get_contents() and strip out any markup (such as the head) that you didn't need.

Alternatively, you could have an iframe in the main page, with a src that called your PHPExcel script.

Feb 11, 2010 at 4:24 AM

Great, ill try it out. Thank you.