<?php

/**
* @author
* @copyright 2012
*/
$header = array(‘First Name’,’Last Name’,’About you Description’);

// Create a array having xls information to print. It could be get from database.
$xls_data_to_print = array(
‘0’=>array(
‘first_name’=> ‘John’,
‘last_name’=> ‘Rawal’,
‘about_info’=> ‘He is a great player.’,
),

‘1’=>array(
‘first_name’=> ‘John1’,
‘last_name’=> ‘Rawal1’,
‘about_info’=> ‘He is a great player1.’,
),

);
$xls_content_row = ”;
foreach($xls_data_to_print as $xls_ky => $xls_val){
// Write a code here to generate XLS file with required details.
// Use $xls_val->title OR $xls_val[‘title’] depending array type.
$rows = array();
$rows[]= $xls_val[‘first_name’];
$rows[]= $xls_val[‘last_name’];
$rows[]= $xls_val[‘about_info’];

$xls_content_row .= implode(“\t”, array_values($rows)) . “\r\n”;
}
$xls_content_header = implode(“\t”, array_values($header));
$xls_content = $xls_content_header.”\n”.$xls_content_row;
$filename = ‘Xls_data_list_’.date(“d_m_Y”);
header(“Content-type: text/plain; charset=UTF-8”);
header(“Content-Disposition: attachment; filename=$filename”);
header(“Content-Type: application/vnd.ms-excel”);
header(“Pragma: no-cache”);
header(“Expires: 0”);
print $xls_content;
exit();
?>

Advertisements