|
1.此导出方法简单,没有乱码问题,不过本质还是xml,所以不能将导出文件导入。(Excel_XML是外部方法,需要Excel_XML外部类)
Class OutOrInService
{
//导出excel
function saveExcel($filename,$sheetname,$data)
{
// $black = new BlackService();
// $data = (array)$black->select("","","","",1);
// $title = Array("id","源ip","目的ip","源端口","访问时间");
// array_unshift($data,$title);
$xls = new Excel_XML('UTF-8', false, $sheetname);
$xls->addArray($data);
$xls->generateXML($filename);
}
//导出html
function saveHtml($filename,$sheetname,$data)
{
header("Content-type: application/html");
header("Content-Disposition: attachment; filename=$filename");
echo "<html>";
echo "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>$sheetname</title></head>";
echo "<body>";
echo "<table>";
foreach ($data as $list)
{
echo "<tr>";
foreach ($list as $key => $value)
{
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
echo "</body>";
echo "</html>";
}
}
使用此类页面
$black = new BlackService();//连接数据库,查询相应表的类
$data = (array)$black ->selectAll($fsrc_ip,$fdst_ip,$fstart_time,$fend_time);
$title = Array("id","源ip","目的ip","源端口","访问时间");//第一行标题
array_unshift($data,$title);//合并
if($type=="excel")
{
$out->saveExcel($filename,"黑名单访问日志",$data);
}
else if($type=="html")
{
$filename=$filename.".html";
$out->saveHtml($filename,"黑名单访问日志",$data);
}
exit(); |
|
|