Have you thought of creating excel files using PHP?
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
John 2250
Ram 1200
Steve 1200
Vinod 1200
Create the php file that will create the excel files for you.
Lets call it: excelgenerate.php
Start with:
require_once “excel.php”;
$filename = “theFile.xls”;
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!
$export_file = “xlsfile://tmp/”.$filename;
$fp = fopen($export_file, “wb”);
if (!is_resource($fp))
{
die(”Cannot open $export_file”);
}
// typically this will be generated/read from a database table
$assoc = array(
array(”First name” => “John”, “IQ” => 2250,
array(”First name” => “Ram”, “IQ” => 1200,
array(”First name” => “Steve”, “IQ” => 1200,
array(”First name” => “Vinod”, “IQ” => 1200);
fwrite($fp, serialize($assoc));
fclose($fp);
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.
header (”Expires: Mon, 26 Jul 1997 05:00:00 GMT”);
header (”Last-Modified: ” . gmdate(”D,d M YH:i:s”) . ” GMT”);
header (”Cache-Control: no-cache, must-revalidate”);
header (”Pragma: no-cache”);
header (”Content-type: application/x-msexcel”);
header (”Content-Disposition: attachment; filename=\”” . $filename . “\”” );
header (”Content-Description: PHP/INTERBASE Generated Data” );
readfile($export_file);
exit;
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
Refrence: PHPClasses.com
Related posts:
- Generating PDF files with PHP and FPDF
- Create PDF using perl
- Perl script for search & replace in several files
- search & replace in several files in perl script
- Access files on the server via sql-injection in PostgreSQL
- Creating graphs and charts in PHP
- Create Your Own Digg Like Portal
- Renaming multiple files simultaneously
- Solve: Cannot modify header information – headers already sent
- List Extract and Compact simple but very useful functions in php

