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();
分享到:
相关推荐
php导入导出Excel,导入Excel,导出Excel,mysql导入导出Excel
PHP导入导出Excel PHP导入导出xls文件
PHP导入导出Excel文件 使用php封装一个excel类 简单快捷使用导入excel文件数据 到数据库里面 也可以调用导出数据库的数据 生成excel文件格式表
使用thinkphp导入导出excel数据
这里实现的PHP导入导出excel功能用到的是开源PHPExcel,执行下面的操作之前请先下载该类库文件,官方网站:http://www.codeplex.com/PHPExcel,官网案例代码很多,导出pdf什么的都有,这里主要介绍PHP导入导出excel...
php根据excel模板导出excel并合并单元格,根据模板导出会少写很多样式的代码,非常方便
excel导入导出.rarexcel导入导出.rarexcel导入导出.rarexcel导入导出.rar
个人做的一个php导入/导出excel表单总结文档,提供了具体的代码,希望思路能帮助到大家!
thinkhphp3.2 excel导入导出demothinkhphp3.2 excel导入导出demothinkhphp3.2 excel导入导出demothinkhphp3.2 excel导入导出demothinkhphp3.2 excel导入导出demothinkhphp3.2 excel导入导出demothinkhphp3.2 excel...
PHP导入和导出CSV EXCEL实例代码 写入读取mysql数据库
php excel导出 导入php excel导出 导入php excel导出 导入php excel导出 导入
基于PHP的excel插件支持7.4(操作Excel实现导入导出).zip
php电子表格 导入/导出excel实例 php电子表格 导入/导出excel实例 php电子表格 导入/导出excel实例 php电子表格 导入/导出excel实例
PHP下导入导出excel,可将excel导入mysql,也可以将数据库中数据导出excel
thinkphp框架 导入导出excel表格 多种方式导出 代码简单明了thinkphp框架 导入导出excel表格 多种方式导出 代码简单明了thinkphp框架 导入导出excel表格 多种方式导出 代码简单明了
PHP开发中遇到的数据导入功能,发现此插件比较好用,实现代码见本人博客。PHPExcel Excel1.8导入导出。
2019年 PHP Excel导入导出 CSV导入导出,thinkphp Excel导入导出 CSV导入导出
php 导出excel php导入excel
本文给大家分享的是PHP将Excel导入数据库以及数据库数据导出至Excel的方法和示例,有需要的小伙伴可以参考下