Welcome Guest, Not a member yet? Register   Sign In
Spry Ajax PHP Codeigniter Smarty - Report in XLS formate header problem
#1

[eluser]kamal1976[/eluser]
Dear Sir,

I am using CI with Spry Adodb Ajax and smarty template. I have problem while creating a Excel file on submit when the submit is through Ajax if its a normal submit promptly starts to down load. Following is the code i am using.

/* make an xls file */
if (! function_exists ( 'makeXLS' ) ) {
function makeXLS( $data, $file, $title ) {
$i = 0;
$xls = "<table border='1' cellpadding='1' cellspacing='0' bgcolor=''>";
$keyrow = "";
$valrow = array();
/* dump ($data);
print("<br>") . $file;
print("<br>") . $title; */

foreach($data as $res) {
$keyrow = "<tr><td colspan='". sizeof($res) ."' bgcolor='#000000' align='center'><font color='#FFFFFF' size='2'><b>$title</b></font></td></tr><tr>";
$valrow[$i] = "<tr>";
foreach((array)$res as $key=>$val) {

/* manual field/display key name mangling here */
switch ($key) {

case "gc_id":
$key = "Global Company ID";
break;
/* case "amount":
$val = "\$" . number_format($val,2);
break;
case "amount_sum":
$val = "\$" . number_format($val,2);
break; */
}

if (preg_match("/amount/i","$key")) {
$val = "\$" . number_format($val,2);
}
if (preg_match("/date/i", "$key")) {

$val = substr($val, 0, -11);
}
$key = preg_replace('/_/', ' ',"$key");
$key = ucwords($key);

/* now add the key and value to the excel output table */
$keyrow .= "<td bgcolor='#cccccc'><b>$key</b></td>";
$valrow[$i] .= "<td>$val</td>";
}
$keyrow .= "</tr>";
$valrow[$i] .= "</tr>";
$i++;
}
$xls .= $keyrow;
foreach ($valrow as $row) {
$xls .= $row;
}
$xls .= "</table>";


header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename= ". $file ." ");
header("Content-Transfer-Encoding: binary ");

print $xls;
exit;
}
}

My submit button with Ajax it is printing my xls file on the html page rather then prompt for the download in xls format.

&lt;form action="/acctls/main/company_records" method="post"
name="get_transactions" id="get_transactions"
&gt;&lt;input
type="hidden" name="form_name" id="form_name" value="get_invoices" />

If I use the same form submit like below it works perfectly but I must use Ajax as its Ajax progression.

&lt;form action="/acctls/main/company_records" method="post"
name="get_transactions" id="get_transactions"&gt;&lt;input
type="hidden" name="form_name" id="form_name" value="get_invoices" />


Can you please guide if its a header setting problem as if the submit is not ajax it works perfectly.
I am keenly waiting for your response.
Regards
Kamal.


Messages In This Thread
Spry Ajax PHP Codeigniter Smarty - Report in XLS formate header problem - by El Forum - 09-30-2008, 12:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB