Close Search Box
Search Box

Search: From:

Close
Newsletter

9Tutorials to your Inbox



Create Excel files with PHP

Create Excel files with PHP
Author lv1 (2000/5000)
8,863 views
1 Star2 Star3Star4 Star5 Star (7 votes, average: 3.71 out of 5)

Have you ever thought of creating excel files from your web site? Excel is a very useful format for lots of purposes. For example, exporting stats, member lists to hand over to economy department etc.

But how can we create a simple excel file with a header and two different columns?
Of course you can sit down and read the excel specifications, and do it your self…
Or the smarter way, download classes from phpclasses.org made by Ignatius Teo.

You use these classes to generate your excel files. Pretty simple, but very effective.
Start with downloading (registrate for free to download), here http://www.phpclasses.org/browse/package/1919.html .
Unzip and upload the file named excel.php to your server.

I am going to generate a simple excel file that will contain Name and IQ in two columns :-)
The file will look something like this (Hopefully):
First name IQ
Mattias 250
Tony 100
Peter 100
Edvard 100

(These numbers are just estimates… ;-)

Create the php file that will create the excel files for you.
Lets call it: generate.php

Start with:

This section will create and save the excel file on the server.
The file will be saved in the directory tmp, as theFile.xls.
The code is pretty self explaining I think. don’t bother with small details, just use it as a tool!

This section is for opening the file directly for the surfer in his browser.
It’s then up to the user to choose if he/she wants to open or save the file.
If you only want to save files on the server, just remove this part from the file.

If you run this code you will get two things:

  1. An excel file in /var/ on your server
  2. This file opened to the user that surf your site

This is the whole tutorial, showing you that it is not that hard to create an excel file or open it to the user.

Copyright @ Gary Logsdon

del.icio.us:Create Excel files with PHP digg:Create Excel files with PHP spurl:Create Excel files with PHP newsvine:Create Excel files with PHP blinklist:Create Excel files with PHP furl:Create Excel files with PHP reddit:Create Excel files with PHP blogmarks:Create Excel files with PHP Y!:Create Excel files with PHP magnolia:Create Excel files with PHP segnalo:Create Excel files with PHP
Login




Friends' Sites

Contact Us

Categories

Sponsors

Featured Links

Post a Comment »








Safari hates me

Comment Guidelines

  • Hyperlinks are automatically generated.
  • <em>italic</em>
  • <strong>bold</strong>