Saturday, 24 September 2016

Export Data to Excel Without Extension in Yii2 Export in Excel yii2

Hello everybody now i will share to you all about export data table to excel file without extension in yii2.
Okay, lets go.
This function is paste in controller and run :

public function actionExportexcel()
{
$Project = Project::find()->all();
$filename = 'test- '.date('Y-m-d').' - hemant.xls';
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=".$filename);
echo '<table width="100%" border="1">
<thead>
<tr>
<th>Project Id</th>
<th>Project Name</th>
<th>Price</th>
<th>Type</th>
<th>Project Description</th>
<th>Address</th>
<th>Amenities</th>
<th>Total Area</th>
<th>Covered Area</th>
<th>Open to Air Area</th>
<th>Roof top Accessibility</th>
<th>Total no. of tower</th>
<th>Total no. of Flats</th>
<th>Banner</th>
</tr>
</thead>';
foreach($Project as $prj){
echo ' 
<tr>
<td>'.$prj->id.'</td>
<td>'.$prj->project_name.'</td>
<td>Min '.$prj->min_price.' - Max '. $prj->max_price.'</td>
<td>type</td>
<td>'.$prj->content.'</td>
<td>'.$prj->address.'</td>
<td>'.$prj->amenities.'</td>
<td>'.$prj->projectfacts->total_area.'</td>
<td>'.$prj->projectfacts->covered_area.'</td>
<td>'.$prj->projectfacts->open_to_air_area.'</td>
<td>'.$prj->projectfacts->roof_top_accessibility.'</td>
<td>'.$prj->projectfacts->no_of_tower.'</td>
<td>'.$prj->projectfacts->no_of_flat.'</td>
<td> <img src="'. $prj->banner_image;'." /></td>
</tr>
';
}
echo '</table>';
}

Result of export excel.



Export Data to Excel Without Extension on Yii2 Export in Excel yii2

2 comments: