tags:

views:

90

answers:

4

Hello.

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.

+1  A: 

Literally, PHPExcel: http://phpexcel.codeplex.com/

Piskvor
He require a php_zip php_gd and php 5.2. Hosting of my customer hasn't this things. And php 5.16. Terrible hosting!
Alexander.Plutov
@Alexander.Plutov: PHP 5.1.6? I feel your pain. Good luck with the search...
Piskvor
Yeah. I have found it.http://dustweb.ru/log/2008/08/01/write_excel_php/
Alexander.Plutov
Some users have reported that PHPExcel will run on 5.1.6, and the php wrapper for zip/unzip binaries ( https://sourceforge.net/project/showfiles.php?group_id=254316 ) can be used instead of php_zip; and gd is only used if you work with images in your worksheets or use autocolumn sizing with rotated texts. However, I can't make any guarantees about that; and while I'm doing some work to try and reduce the requirements, it isn't priority.
Mark Baker
A: 

It's a little-known format that never really caught on, but MS Office has support for so-called Excel 2003 XML files - which are indeed XML and, at a bare minimum, look like this:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
  <Worksheet>
    <Row>
      <Cell>
        <Data ss:Type="String">First</Data>
      </Cell>
    </Row>
   </Worksheet>
 </Workbook>

You could generate this quite simply without any PHP extensions, and it will open correctly in any version of MS Excel since 2003. OpenOffice 2 and 3 will open these correctly if you rename the file extension to .xls.xml

When a user opens this file and saves it from Excel, it will be, by default, converted to the classic XLS file.

As @Alexander.Plutov notes in a comment, there is a library for writing these files.

There's a useful (and more comprehensive) page on IBM's site about this format and PHP: http://www.ibm.com/developerworks/opensource/library/os-phpexcel/#N101F7

Piskvor
I wonder where this answer is supposed to be wrong; I've successfully used the Excel 2003 XML format this way, on several occasions, and it works. Care to comment?
Piskvor
I didn't downvote, but I suspect it could be the use of string concatenation to build an xml file rather than XMLWriter or similar
Mark Baker
@Mark Baker: Could be. I mentioned that to show that in an extreme case, no libraries are strictly necessary (had to do that once, in a constrained environment; but I agree that using a XMLWriter for writing XML makes sense in most cases). Edited that out.
Piskvor
+1  A: 

Im using http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/

I got it simply included in many projects and it works like a charm.

palmic
+2  A: 

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.

Hans