tags:

views:

93

answers:

6

I have .xls file.

How Can i write or append content to the excel using PHP fwrite().

In waht format i write to that. When i try using fwrite its showing an error message in excel 2007

what seperator i can use? Is it possible with out excel classes

A: 

to write you can use : Spreadsheet_Excel_Writer is a tool for creating Excel files without the need for COM components

http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php but you cant appaend to file , only to create it.

or using phpexcel (support excel 2007)

http://phpexcel.codeplex.com/

and you can append see a example :

http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=82996

Haim Evgi
A: 

if you just want/need to create a very simple table, you just need to make a *.csv-file which can be opened by excel - but not: you can't use formulas in this and you can't do any kind of formatting.

oezi
Actually, you can use formulas in a CSV file, though you have to take more care that the formula references the correct rows and columns: R1C1 format is often easier to use than A1 format addressing.
Mark Baker
A: 

You can use the PHPExcel library, to read an existing Excel file, add new rows/columns to it, then write it back as a real Excel file.

Disclaimer: I am one of the authors of this library.

Mark Baker
Thanks . As you are the other can i ask you something.How wil be performance if i write more than 65000 records. Is there any option to add another sheet when it reaches the excel max limit 65536 rows?
zod
PHPExcel is a full-fledged Excel library, so yes... it does handle multiple worksheets. Be warned, it's slow and memory-hungry when working with large volumes of row/column data, although most libraries seem to be slow and memory-hungry when working with large volumes... there are some tricks that can improve things depending on your exact needs. The 65536 row limit only applies with BIFF5 or 8 .xls files. MS Office OpenXML format (used by Excel 2007 and 2010) can have a million rows in a worksheet.
Mark Baker
+1  A: 

You can try and create a CSV file, like this:

name;surname;blabla
name;surname;blabla
name;surname;blabla
name;surname;blabla

Excel should eat this :)

It is convenient to use PHP CVS functions: http://php.net/manual/en/function.fputcsv.php

Silver Light
A: 

you can try this library http://phpexcel.codeplex.com/

or you can create .csv file for example and then import them to excel.

samrockon
A: 

I wrote a simple library for exporting Excel-friendly XML files from PHP: http://github.com/elidickinson/php-export-data

Eli