【发布时间】:2014-01-30 12:56:06
【问题描述】:
我有评论计数的用户列表。我有使用下面的库和代码导出 excel。 如何在 Excel 工作表中包含图表。
这是我的输出: 例如:
Sno USER CommentCount
1 User1 10
2 User2 12
3 User3 21
如何使用 codeigniter 在 Excel 中形成图形或图表。
图书馆功能:
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>';
}
}
控制器代码:
public function userlist(){
$sql = $this->export_model->user_export();
$this->export->to_excel($sql, 'UserList');
}
【问题讨论】:
标签: php codeigniter graph charts pchart