2

I want to create a simple excel file with two rows. example:

order id | Name | Address | Quantity | Price | Total
    1    | XXXX | YYYYYYY |     10   |  700  |  7000

Is there any lightweight library or some code snippet so that I can easily achieve this.

4
  • xls and xlsx are both pretty involved formats, you will most likely need a heavy library Commented Feb 25, 2012 at 4:33
  • If you want an actual XLS or XLSX then phpexcel is your best bet regardless of the size of the library. If you can deal with just handing them a CSV then or a HTML table then do that and force a download or what have you. Commented Feb 25, 2012 at 4:35
  • @prodigitalson: I want excel file with .xls extention. I just downloaded PHPExcel and I found that It contains 19.9 MB classes folder. I dont think so to generate such a small content it requires that much big library. Commented Feb 25, 2012 at 4:56
  • The most easy way is here stackoverflow.com/questions/11189021/reports-in-codeigniter Commented Jun 25, 2012 at 13:37

3 Answers 3

5

See this tutorial:

Here's a small (2.7 KB zipped) library to export XLS:

Here's a similar one to export XLSX (4.4 KB zipped):

Both have small working examples.

Sign up to request clarification or add additional context in comments.

8 Comments

I dont want PEAR libraries to installation.
Sorry, didn't think when you said "lightweight" that you mean no PEAR. Did you see this: code.google.com/p/php-excel? I don't know how lightweight you can go in Excel case...
I just downloaded PHPExcel and I found that It contains 19.9 MB classes folder. I dont think so to generate such a small content it requires that much big library.
The zip file is 4.4 KB: code.google.com/p/php-excel/downloads/…. Is this the one you downloaded? It generates xslx, though.
|
2

This has been answered at the following link:

How to use the CSV MIME-type?

Although it outputs a CSV MIME type, Excel is usually the default application for CSV.

Oops. Forgot the CodeIgniter part :)

Based on the above link, you can create a controller similar to the following, assuming CI 2.x

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Csv extends CI_Controller {

    public function index() {
        header('Content-type: text/csv');
        header('Content-disposition: attachment;filename=fromci.csv');
        echo "order,id,Name,Address,Quantity,Price,Total".PHP_EOL;
        echo "1,1,XXXX,YYYYYYY,10,700,7000".PHP_EOL;
    }
}

5 Comments

I want excel file with .xls extention.
You're going to need a library since .xls is a binary format. CSV is a simple way to get Excel to open and the user can save as .xls if desired.
Sorry, but its my need. Dont ask why.
Requirements are requirements :)
Yup. we can't say anything beyond that :)
0

This excel.php file could prove useful to you as an alternative to php-excel. I've never personally used it, but the description sounds like it could work for you.

http://www.phpclasses.org/package/1919-PHP-Stream-wrapper-to-read-and-write-MS-Excel-files.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.