I needed to create a script to output an Excel file and had no idea how to do it. Searching google I found lots of classes to accomplish this but they all looked to be way to complicated for a simple task. Having now done this the easy way I thought I should post a quick and simple complete script for anybody else looking to do this. <?php $line1="ID\tProduct\tColor\tSales\t"; $line2="1\tPrinter\tGrey\t13\t"; $line3="2\tCD\tBlue\t15\t"; $line4="3\tDVD\tRed\t7\t"; $line5="4\tMonitor\tGreen\t4\t"; $line6="5\tTelephone\tBlack\t2\t"; $data="$line1\n$line2\n$line3\n$line4\n$line5\n$line6\n"; header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=extraction.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; ?> PHP: Thats all you need for a simple spreadsheet. Open up this file in your browser and see what you get. The basics are using \n for a line break and \t for a column break. Hope this is useful for somebody.
Great info. Do you know how to create a file in excel formatted csv? Also, Is there any way to pre-format columns, for say zip codes or some other excel format?
To create a csv I think you would change the header to be a .csv file instead of a .xls and follow the standard csv format rather than using \t for a column break. I am sure that the classes available have many more functions (some even can draw charts) but haven't investigated them in depth.
The solution mad4 shows is good, i may self have found the need for php-excel currently i use the pear package excel writer and have to say it is fairly easy to use, with the exception of sheets required large amounts of formating. However in the early stages i found this article to be more than usefull and game me some advanced uses, using the basic function as shown above. http://www.phpfreaks.com/tutorials/114/0.php
Hate to dig up old topics, but does anyone have a php script / function / class etc., that will convert an excel file back to php? I need to pull a file from excel into php, not into mysql!
php isn't suitable for storing the data from an excel file. Can you not store the data in a text file or sql database?
You can import excel file if it is in flat file format. You will ofcourse lose the formating and such
I know how to do it with a .csv or tab delimited text file. I would like to figure out how to do it with a .xls file instead. I only need the first sheet of the document and I don't need to keep any excel formatting. Saving it as a csv adds an extra step, and for this purpose it creates a lot of extra work.
Hey, any ideas on how this could be done without the need of creating a new excel spreadsheet? What I am looking to do is simply write into an existing excel spreadsheet so that I may view it at a later point. Any help would be much appreciated! Milky Joe