EXCEL导出方式之HEADER导出HTML
2016-12-09 08:53
417 查看
直接用header导出html,指定样式的excel
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript">
$(document).ready(function () {
$('#search').click(function(){
$('#stock-form').attr('action','');
});
$('#export').on('click',function(){
$('#stock-form').attr('action','cars/export');
$('#stock-form').submit();
});
});
</script>
附PHPEXCEL模式导出
<?php
$param = array();
#####***********时间查询**************######
$param['start'] = $_GET['start'];
$param['end'] = $_GET['end'];
#####***********时间查询**************######
*********************其他代码部分************************
//$arrayList 结果集:获取满足当前条件的数据
require ./phpexcel/Classes/PHPExcel.php';
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了4列
$letter = array('A','B','C','D');
//表头数组
$tableheader = array('模拟EXCEL表格A','模拟EXCEL表格B','模拟EXCEL表格C','模拟EXCEL表格D');//第一行表头
//填充表头信息
for($i = 0;$i < count($tableheader);$i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
}
//填充表格信息
for ($i = 2;$i <= count($arrayList) + 1;$i++) {//第二行开始
$excel->getActiveSheet()->setCellValue("$letter[0]$i",$arrayList[$i-2]['excelA']);
$excel->getActiveSheet()->setCellValue("$letter[1]$i",$arrayList[$i-2]['excelB']);
$excel->getActiveSheet()->setCellValue("$letter[2]$i",$arrayList[$i-2]['excelC']);
$excel->getActiveSheet()->setCellValue("$letter[3]$i",$arrayList[$i-2]['excelD']);
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel5($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Disposition: attachment; filename=表格名称_".date('Y-m-d h:i:s').".xls");
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
?>
<form method="get" id="stock-form"> <div class="form-group"> <input placeholder="开始时间" type="text" class="laydate-icon form-control" style="width:240px;" name="start" id="start" value="<?php if (isset($param['start'])) { echo $param['start'];} ?>" readonly> </div> <div class="form-group"> <input placeholder="结束时间" type="text" class="laydate-icon form-control" style="width:240px; margin-top:5px;" name="end" id="end" value="<?php if (isset($param['end'])) { echo $param['end'];} ?>" readonly> </div> <div class="form-group sear_rt"> <button type="submit" id="search" class="btn btn-success">搜索</button> </div> <div class="clear"></div> <div class="form-group sear_rt"> <button type="button" id="export" class="btn btn-success">导出</button> </div> </form>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript">
$(document).ready(function () {
$('#search').click(function(){
$('#stock-form').attr('action','');
});
$('#export').on('click',function(){
$('#stock-form').attr('action','cars/export');
$('#stock-form').submit();
});
});
</script>
<?php $param = array(); #####***********时间查询**************###### $param['start'] = $_GET['start']; $param['end'] = $_GET['end']; #####***********时间查询**************###### *********************其他代码部分************************ //$arrayList 结果集:获取满足当前条件的数据 //创建展示表格 $strTable ='<table width="100%" border="1">'; $strTable .= '<tr>'; $strTable .= '<td style="text-align:center;font-size:14px;" height="30" width="80">模拟EXCEL表格A</td>'; $strTable .= '<td style="text-align:center;font-size:14px;" height="30" width="80">模拟EXCEL表格B</td>'; $strTable .= '<td style="text-align:center;font-size:14px;" height="30" width="80">模拟EXCEL表格C</td>'; $strTable .= '</tr>'; foreach($arrayList as $k=>$val){ $strTable .= '<tr>'; $strTable .= '<td style="text-align:center;font-size:14px;" height="30" width="80">'.$val['excelA'].'</td>'; $strTable .= '<td style="text-align:center;font-size:14px;" height="30" width="80">'.$val['excelB'].'</td>'; $strTable .= '<td style="text-align:center;font-size:14px;" height="30" width="80">'.$val['excelC'].'</td>'; $strTable .= '</tr>'; } $strTable .='</table>'; unset($arrayList); header("Content-type: application/vnd.ms-excel"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=表格名称_".date('Y-m-d h:i:s').".xls"); header('Expires:0'); header('Pragma:public'); echo $strTable; exit(); ?>
附PHPEXCEL模式导出
<?php
$param = array();
#####***********时间查询**************######
$param['start'] = $_GET['start'];
$param['end'] = $_GET['end'];
#####***********时间查询**************######
*********************其他代码部分************************
//$arrayList 结果集:获取满足当前条件的数据
require ./phpexcel/Classes/PHPExcel.php';
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了4列
$letter = array('A','B','C','D');
//表头数组
$tableheader = array('模拟EXCEL表格A','模拟EXCEL表格B','模拟EXCEL表格C','模拟EXCEL表格D');//第一行表头
//填充表头信息
for($i = 0;$i < count($tableheader);$i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
}
//填充表格信息
for ($i = 2;$i <= count($arrayList) + 1;$i++) {//第二行开始
$excel->getActiveSheet()->setCellValue("$letter[0]$i",$arrayList[$i-2]['excelA']);
$excel->getActiveSheet()->setCellValue("$letter[1]$i",$arrayList[$i-2]['excelB']);
$excel->getActiveSheet()->setCellValue("$letter[2]$i",$arrayList[$i-2]['excelC']);
$excel->getActiveSheet()->setCellValue("$letter[3]$i",$arrayList[$i-2]['excelD']);
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel5($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Disposition: attachment; filename=表格名称_".date('Y-m-d h:i:s').".xls");
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
?>
相关文章推荐
- DataGridView扩展方法行号、全选、导出到Excel(引用excel组件、生成html两种方式)
- C# HTML方式导出至Excel
- pb9中使用htmltable方式将数据窗口导出为excel文件的几点看法
- DataGridView扩展方法行号、全选、导出到Excel(引用excel组件、生成html两种方式)
- 导出EXCEL【Web方式HTML通过拼接html中table】
- js将html中的内容导出word、或者excel文件的方法
- 利用获取页面html,导出excel
- DataGrid系列技巧(导出excel,事件,多种方式呈现数据,全选全删)等等等 (转)
- javascript 导出html table到 excel(转载)
- 导出excel的两种方式
- html页面表格导出到excel总结
- datagrid数据导出到excel文件给客户端下载的几种方法 (xls,csv,html)
- 从datagrid导出html代码,生成excel文件,给客户端下载
- 导出Excel的方法,传入为table或html!
- datagridview导出Excel(以流的方式)
- 一种值得推荐的导出到EXCEL文件方式
- JSP应用导出Excel报表的简单实现以及中文乱码彻底解决(HTML)(转)
- 导出Excel的几种方式
- html表格数据导出EXCEL
- 用 HTML 格式导出 Excel 时,如何保留显示网格线