I'm able to save the excel file as .csv using perl like this :
print "Content-type: application/vnd.ms-excel\n";
print "Content-Disposition: attachment;filename=\"file name.xls\"\n\n";
print"Fruits, Cost";
#Then looping on the results.
Yet I need to save this as .xls cause I want to use colours. Any one can help?
http://www.ibm.com/developerworks/library/l-pexcel/
http://search.cpan.org/dist/DBD-Excel/
I highly recommend Spreadsheet::WriteExcel for your needs. The library is entirely written in Perl, so all you need to do is upload the CPAN library to your web site and specify the specific location. The library documentation and the code snippet below should get you started.
If you don't need super-fancy functionality such as rich text, you can use Spreadsheet::WriteExcel which works quite nicely and is pretty low-overhead too.
Edit: use
my $workbook = Spreadsheet::WriteExcel->new('-');
to have your workbook written directly to STDOUT.