php 方便快捷导出excel
2016-09-22 16:58
225 查看
/** * 导出excel * @param array $column * eg: $column = [ * 'username' => '姓名', * 'age' => '年龄', * 'sex' => '性别' * ] * @param array $data * eg: $data = [ * ['username' => 'yht', 'age'=>20, 'sex'=>'男'], * ['username' => 'jsh', 'age'=>18, 'sex'=>'女'], * ['username' => 'klerk', 'age'=>25, 'sex'=>'男'], * ] */ public static function exportExcel($column, $data) { $keys = array_keys($column); header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=export_data.xls"); $html = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">'; $html .= ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $html .= ' <html> '; $html .= ' <head> '; $html .= ' <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> '; $html .= ' <style id="Classeur1_16681_Styles"></style> '; $html .= ' </head> '; $html .= ' <body border=1> '; $html .= ' <div id="Classeur1_16681" align=center x:publishsource="Excel"> '; $html .= ' <table x:str border=1 cellpadding=1 cellspacing=1 width=100% style="border-collapse: collapse">'; $html .= ' <tr>'; foreach($column as $key => $value){ $html .= ' <td>' . Html::encode($value) . '</td>'; } $html .= ' </tr>'; if($data) { foreach ($data as $key => $value) { $html .= ' <tr>'; foreach ($keys as $val){ $html .= ' <td>' . $value[$val] . '</td>'; } $html .= ' </tr>'; } } $html .= ' </table> '; $html .= ' </div> '; $html .= ' </body> '; $html .= ' </html> '; echo $html; }
相关文章推荐
- 快捷方便的Excel导入导出工具 Easy-Xls 1.0 版本发布
- JAVA原始的导出excel文件,快捷通用 方便 还能够导出word文档哦
- 使用CLR存储过程方便快捷导出数据到Excel 【转】
- 使用CLR存储过程方便快捷导出数据到Excel
- PHP导入导出Excel方法小结
- php导出Excel php导入Excel PhpExcel使用说明 PhpExcel使用手册
- PHP导出Excel 之 Spreadsheet_Excel_Writer
- oracle 方便快捷的数据导入/导出命令
- PHP导入导出Excel方法小结
- 总结 php导出Excel php导入Excel PhpExcel使用说明 PhpExcel使用手册
- php导出excel
- Php代码实现将mysql数据库导出为excel表格形式
- 用php+MSSQL 开发的,如何将查询的数据导出到EXCEL中.
- php数据导入导出之excel(csv文件)
- PHP导入导出Excel方法小结
- PHP导出Excel 之 Spreadsheet_Excel_Writer
- PHP导出MySQL数据库为EXCEL文件格式(.xls)的方法 http://www.kankanblog.com/read.php/144.htm
- 用php_writeexcel导出excel
- php数据导入导出之excel(csv文件)
- PHP导出Excel文件