I want a excel sheet to download using PHP.
In excel report, numbers generated are not displaying properly in cell.
I want to display numbers properly in the cell.
My code:
<?php
include("connection.php");
if(isset($_POST['submit']) && $_POST['submit']=="Download")
{
$payor_code = $_POST['payor_code'];
$corp_code= $_POST['corp_code'];
$pro_type = isset($_POST['product_type']);
$submit_date = $_POST['sub_date'];
$sql= oci_parse($conn, "select * from members");
oci_execute($sql);
$dat = date("d/m/Y");
//echo $dat;
$filename = "Report_$dat";
$table = "";
$table .= '<table border="1" cellpadding="2" cellspacing="0" width="900">';
$table .= '<tr>';
$table .= '<td colspan="20" style="height:30px;font-weight:bold; font-size:20px" align="center">' .$filename. '</td>';
$table .= '</tr>';
$table .= '<tr>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">ReceivedDate</td>';
$table .= '<td style="height:20px;font-weight:bold;width=50px" align="center" valign="middle">ProductType</td>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">Name</td>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">SubmissionDate</td>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">ClaimNo</td>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">PatientName</td>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">PatientIC</td>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">PrincipalName</td>';
$table .= '<td style="height:20px;font-weight:bold;width=100px" align="center" valign="middle">PrincipalIC</td>';
$table .= '</tr>';
$i = 1;
while($row = oci_fetch_array($sql))
{
$cli_id = $row['CLAIMS_ID']. "<br>\n";
$pat_name = $row['PATIENT_NAME']. "<br>\n";
$sub_date = $row['SUBMISSION_DATE']. "<br>\n";
$remarks= $row['REMARKS']. "<br>\n";
$doc_rece_date= $row['RECEIVED_DATE']. "<br>\n";
$group = "Group";
$test = "TEST";
$board_type = "TEST";
$board_no = "123";
$prin_name = "Test";
$table .= '<tr>';
$table .= '<td align="left">'.$doc_rece_date.'</td>';
$table .= '<td align="left">'.$group.'</td>';
$table .= '<td align="left">'.$test.'</td>';
$table .= '<td align="left">'.$sub_date.'</td>';
$table .= '<td align="left">'.$cli_id.'</td>';
$table .= '<td align="left">'.$pat_name.'</td>';
$pat_ic = $row['NRIC_ID'];
$table .= '<td align="left">'.$pat_ic.'</td>';
$pric_name = $row['EMP_NAME'];
$table .= '<td align="left">'.$pric_name.'</td>';
$pric_ic = $row['PRINCIPAL_NRIC'];
$table .= '<td align="left">'.$pric_ic.'</td>';
}
$table .= '</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=$filename.xls");
header("Content-Transfer-Encoding: binary ");
echo $table;
}
?>