session_start();
include "db_connect/config_db.php";//DB CONNECTIVITY
include "db_connect/db_connect.php";
include "library/functions.php";
$xlshead=pack("s*", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
$xlsfoot=pack("s*", 0x0A, 0x00);
function xlsCell($row,$col,$val)
{
$len=strlen($val);
return pack("s*",0x204,8+$len,$row,$col,0x0,$len).$val;
}
$data=
xlsCell(0,0,"Name")
. xlsCell(0,1,"Salary") ;
$rowNumber=0;
$q="select name,salary from employee";
$r=mysql_query($q,$con);
while($row=mysql_fetch_array($r)) {
$rowNumber=$rowNumber+1;
$name=$row['name'];
$tot=$row['salary'];
$salary=floatval($tot);
$data.=xlsCell($rowNumber,0,$name) . xlsCell($rowNumber,1,$salary) ;
}
$filename="users.xls";
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary ");
echo $xlshead . $data . $xlsfoot;
exit; //this is important!
This code helps me to export data into a excel successfully.
Exported values are not recognized in SUM function.
I think error is Salary values are not stored in Value format.values are stored in Text Format.
I tried to change the value format using floatval function and Numberformat.But gives same error.
Please advise.
Thanks in advance.

New Topic/Question
Reply



MultiQuote




|