Thursday, February 21, 2013

CSV sheet in php

 <?php
$test='
<table width="100%" border="0" cellspacing="1" >
<tr>
<td width="20%" class="body-table-heading-bg" style="color:#000000;">Test</td>
<td width="10%" class="body-table-heading-bg" style="color:#000000;">Test</td>
<td width="10%" class="body-table-heading-bg" style="color:#000000;">Test</td>
<td width="10%" class="body-table-heading-bg" style="color:#000000;">Test</td>
<td width="10%" class="body-table-heading-bg" style="color:#000000;">Test</td>
<td width="10%" class="body-table-heading-bg" style="color:#000000;">Test</td>
<td width="15%" class="body-table-heading-bg" style="color:#000000;">Test</td>
<td width="15%" class="body-table-heading-bg" style="color:#000000;">Test</td>
</tr>';

while($row=mysql_fetch_array($query))
{
$uid=$row['assigned_to'];
$t2=strtotime($row['creation_ts']);
$t1=strtotime($row['delta_ts']);
$diff = $t1 - $t2;
$hours = $diff / ( 60 * 60 );
$num=number_format($hours, 2, '.', '');
$test.='<tr >
<td width="20%" class="body-table-heading-bg">'.$row[short_desc].'</td>
<td width="10%" class="body-table-heading-bg">'.getProjectname($row[component_id]).'</td>
<td width="10%" class="body-table-heading-bg">'.$num.'</td>
<td width="10%" class="body-table-heading-bg">'.getUser($uid).'</td>
<td width="10%" class="body-table-heading-bg">';
 if($row['bug_status']=="IN_PROGRESS")
{
$test.='<font color="red">'.$row[bug_status].'</font>';
}
else
{
if($row['bug_status']=="RESOLVED")
{
$test.='<font color="green">'.$row[bug_status].'</font>';
}
else
{
$test.='<font color="red">'.$row[bug_status].'</font>';
}
}
$test.='</td>
<td width="15%" class="body-table-heading-bg">'.$row[version].'</td>
<td width="15%" class="body-table-heading-bg">'.$row[creation_ts].'</td>
<td width="15%" class="body-table-heading-bg">'.$row[delta_ts].'</td>
</tr>';

}
echo $test;
$_SESSION['excel_data']=$test;

?>








<?php
session_start();
include("function.php");
$type=$_GET['type'];
$date=date('d-m-Y');
$filename=$type."USER_Report_".$_SESSION['type'].'_'.$date;
$file=$filename.".xls";

$excel_data1=$_SESSION['excel_data'];

$test=$excel_data1;
$data1.='<table  align="center" style="border-collapse: collapse" width="100%">
<tr>
<td><strong>User Name</strong></td> <td><strong>Start Date(d-m-y)</strong></td><td><strong>End Date(d-m-y)</strong></td></tr>

 <tr> 
 <td>'.getUser($_SESSION['userid']).'</td>
 

 

   <td>'.changeDate($_SESSION['start']).'</td>
 
 
   <td>'.changeDate($_SESSION['end']).'</td>
  </tr>
  <tr>
  <td>&nbsp;</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
  <td>&nbsp;</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
  <td>&nbsp;</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td colspan="8" nowrap="nowrap">'.$test.'</td>
  </tr>
 
 
  </table>';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $data1;
?>

No comments:

Post a Comment

Thank you for your Comment....

Popular Posts