2

I'd like to be able to output data to a spreadsheet and have been looking at various packages such as PHPExcel and some of the others listed here Alternative for PHP_excel

simply put I want to write specific text into specified cells & colour code certain cells if possible. which is the simplest form of doing so?

Community
  • 1
  • 1
JustSomeDev
  • 324
  • 5
  • 18

3 Answers3

4

If you want cell formatting such as colour, then I'd certainly recommend PHPExcel... although I do have a certain developer's bias.

Despite offering a wide range of additional features, it is easy to use. You don't specify what format of Excel file you want to write, Excel BIFF file or Office Open XML: PHPExcel offers both. It's still supported (unlike many of the alternatives); and there's a lot of examples showing how to use it in the library package itself, and a helpful message board.

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • having real difficulty getting the PHPExcel tests to work, keep getting the ZipArchive not found error even though I have enabled all the prerequisites in the php.ini. I dont know what Excel BIFF is so I assume the avenue im pursuing at the moment is Office Open XML as I am trying to write the spreadsheet data in xml format. Im writing the xml data simply by writing text data to a file, is this the correct way to do it or is there a better way? – JustSomeDev Apr 08 '12 at 21:54
  • Is every single test in the /Tests directory failing? e.g. 01simple.php? – Mark Baker Apr 08 '12 at 22:30
  • I haven't tried all the tests, but 01simple.php is one of the ones I tested giving the ZipArchive error. I have started creating my spreadsheet using this tutorial http://zaheen.wordpress.com/2010/02/06/writting-xml-with-php-xmlwriter-tutorial/ i'll see how far that get me – JustSomeDev Apr 09 '12 at 12:22
  • Assumptions: you've updated the correct php.ini; php_zip is in your extension_dir; you've restarted your web server; you've checked the webserver logs for any errors on restart. – Mark Baker Apr 09 '12 at 19:19
  • I've done all of the above except checking the logs....I know I know first place i should have looked :) ive stopped trying with PHPExcel, instead im using xmlwriter to write the excel xml which is working quite well. also, im marking this as answer because you were the first to highlight Office Open XML - thanks – JustSomeDev Apr 11 '12 at 17:14
0

Apart from the "coloring" part, I would definitely suggest you go for CSV files (perfectly supported by ALL spreadsheet programs) :

A comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. Plain text means that the file is a sequence of characters, with no data that has to be interpreted instead, as binary numbers. A CSV file consists of any number of records, separated by line breaks of some kind; each record consists of fields, separated by some other character or string, most commonly a literal TAB or comma. Usually, all records have an identical sequence of fields.

Example :

Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
0

If you are not interested in using PHP Excel you can consider CSV format.

This links should help you. http://php.net/manual/en/function.fgetcsv.php http://www.imf.org/external/help/csv.htm

But keep in mind in csv cells or rows cant have any property like in your case colour code. An excel file can simply be saved as a csv file in excel itself

IF csv is not your liking consider Open Document format which will be eaiser to edit than excel's proprietary xml. But excel may need a plugin(OpenXML/ODF Translator Add-in for Office) to read it

Look at http://sourceforge.net/projects/ods-php/

You can also read this http://www.oasus.ca/ODS_V2.pdf

aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242
  • not so much that im not keen, it just seemed overkill. however i need to be able to format the cells so i think ill give phpexcel another look – JustSomeDev Apr 08 '12 at 18:20
  • I'll not be the only person using the outputted file so preferably no 3rd party plug ins should be needed. I've started to write an Office Open XML document using XMLWriter class which seems straight forward so i'll continue with that for now. – JustSomeDev Apr 09 '12 at 12:29
  • cool...but you will need OpenXML/ODF Translator Add-in for Office. also llok at http://www.oasus.ca/ODS_V2.pdf – aWebDeveloper Apr 10 '12 at 06:37