I used this function to export,
where $query variable holds the mysql query which is sent as a parameter,
and in $fieldname variable, array of fieldnames to display header.
everything is ok, n works properly.
one thing i cudn't do was merging cells....
function to_excel_export($query,$fieldName)
{
$filename = date('d-m-Y');
$headers = '';
$data = '';
$obj =& get_instance();
if ($query->num_rows() == 0)
{
echo '<p>The table appears to have no data.</p>';
}
else
{
for($i=0;$i<sizeof($fieldName);$i++)
{
$headers .= $fieldName[$i] . "\t";
}
foreach ($query->result() as $row)
{
$line = '';
foreach($row as $value)
{
if ((!isset($value)) OR ($value == ""))
{
$value = "\t";
}
else
{
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$filename.xls");
$compName = 'C O M P A N Y - N A M E ';
echo $compName."\n\n";
echo $headers."\n".$data;
}
}
$compName = 'C O M P A N Y - N A M E ';
echo $compName."\n\n";
how to merge the cells to display the name which is in $compName variable.