Import Data from Excel

Importing Data from the excel sheet can be done in php on following way,


require_once ‘reader.php’;



function parseExcel($excel_file_name_with_path)
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.


for ($i = 1; $i <= $data->sheets[0][‘numRows’]; $i++) {
for ($j = 1; $j <= $data->sheets[0][‘numCols’]; $j++) {

return $product;

The above code, will read the content from the test.xls  and import to the string which can later on to upload in the table or just print the value.

Here ‘reader.php’ used as the library to read data from the excel, that can be download from the following url.

Export to Excel:

To export data from table to excel can done same as the above except adding this header to tell the php to content will redirect to excel.

header(“Content-type: application/octet-stream”);
header(“Content-Disposition: attachment; filename=test_list.xls”);
header(“Pragma: no-cache”);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: