Search code examples
phpexcelpearxls

PHP Excel, but no Spreadsheet_Excel_Writer


I need to save some data in .xls file. I am trying to use PEAR library Spreadsheet_Excel_Writer. It is work. But now i am working with hosting without PEAR. Of cause, it is very terrible.

Spreadsheet_Excel_Writer has a lot of dependencies. I need a module or code, which i can include in my scripts.

Thx.


Solution

  • I use Spreadsheet Writer a lot and it's nice to have, but if you don't need multiple sheets or the ability to do some formatting, etc, you an always just output HTML and send a

    header("Content-type: application/vnd.ms-excel")
    

    and an extension of ".xls" and then Excel or OpenOffice's spreadsheet program (and I assume, I guess, Mac's spreadsheet program) will open it and format the HTML as a spreadsheet.

    It's not a native solution but in the end, it looks pretty good to the end-user. You have to use tables in your html but you can add colors/borders, padding, font changes, rowspan, colspan, etc, for a bit of control. No functions or formulas or multiple sheets, though.