I have the userlist with comment count.I have export excel using below libaraies and codes. How to include graph inside the excel sheet.
Here is my output: E.g.:
Sno USER CommentCount
1 User1 10
2 User2 12
3 User3 21
How to form graph or chart inside the excel using codeigniter.
Library function:
class Export{
function to_excel($array, $filename) {
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename='.$filename.'.xls');
$h = array();
foreach($array as $row){
foreach($row as $key=>$val){
if(!in_array($key, $h)){
$h[] = $key;
}
}
}
echo '<table><tr>';
foreach($h as $key) {
$key = ucwords($key);
echo '<th>'.$key.'</th>';
}
echo '</tr>';
foreach($array as $row){
echo '<tr>';
foreach($row as $val)
$this->writeRow($val);
}
echo '</tr>';
echo '</table>';
}
function writeRow($val) {
echo '<td>'.utf8_decode($val).'</td>';
}
}
Controller code:
public function userlist(){
$sql = $this->export_model->user_export();
$this->export->to_excel($sql, 'UserList');
}