onethink导出excel
function customer_daochu()
{
/**
* 客户名单导出
*
*/
$customer = D('WcoaUCustomers');
$data = $customer->join("customers_system p on customers.customersid = p.customers_system_id ")->field("customersid,customername,customercode,phone,belong_deptid,belong_employeesid")->select();
$list = array();
$list1 = array();
foreach($data as $v)
{
$list1[0] = $v['customersid'];
$list1[1] = $v['customername'];
$list1[2] = $v['customercode'];
$list1[3] = $v['phone'];
$dept = D('Dept')->field('deptname')->where("deptid = {$v['belong_deptid']}")->find();
$list1[4] = $dept['deptname'];
$em = D('Employees')->field('employeename')->where("employeesid = {$v['belong_employeesid']}")->find();
$list1[5] = $em['employeename'];
array_push($list,$list1);
}
$headArr = array('id','姓名','编号','手机','所属部门','所属员工');
$fileName = "customer";
$this->exportExcel($fileName,$headArr,$list);
}
public function exportExcel($expTitle,$expCellName,$expTableData) //$expTitle=>表的主题,$expCellName=>表头名(列名),$expTableData=>数据(以下采用数字索引数组)
{
$xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
$fileName = '客户表'.date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
$cellNum = count($expCellName); //多少列
$dataNum = count($expTableData); //多少行
Vendor("PHPExcel"); $objPHPExcel = new \PHPExcel(); //初始化
$cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ'); $objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $fileName); //标题
for($i=0;$i<$cellNum;$i++){
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'2', $expCellName[$i]); //表头(列名)
}
// Miscellaneous glyphs, UTF-8
for($i=0;$i<$dataNum;$i++){
for($j=0;$j<$cellNum;$j++){
$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), $expTableData[$i][$j]); //内容
}
}
//可以改格式,剩下不懂了
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xlsx"');
header("Content-Disposition:attachment;filename=$fileName.xlsx");//attachment新窗口打印inline本窗口打印
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}
PHPExcel的存放位置跟导入excel位置一样!
onethink导出excel的更多相关文章
- 【PHP】导入、导出Excel表格(有使用PHPExcel和不使用的两个版本)
		------------ 首先,导出excel ---------------- 一.不使用PHPExcel的版本,很简单的一个方法,简洁.推荐 很简单的导出一个exc ... 
- C#使用Aspose.Cells导出Excel简单实现
		首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ... 
- 利用poi导出Excel
		import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ... 
- [django]数据导出excel升级强化版(很强大!)
		不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ... 
- NPOI导出Excel
		using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ... 
- ASP.NET Core 导入导出Excel xlsx 文件
		ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ... 
- asp.net DataTable导出Excel 自定义列名
		1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ... 
- Aspose.Cells导出Excel(1)
		利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ... 
- 前端导出Excel兼容写法
		今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ... 
随机推荐
- Cheatsheet: 2016 08.01 ~ 08.31
			.NET Getting Started with ASP.NET Core and VS Code Coding Standard Best Practices In C# Wire – Writi ... 
- arguments的理解
			(function(){ return typeof arguments; })(); 无聊的时候看看网上的面试题.个人认为通过面试题可以对某个知识点能够更加认识,踩过坑才会明白坑是有多大.代码中经常 ... 
- 防止SQL注入的方法
			方法1⃣️addslashes(); $username=addslashes($_POST['username']); 方法2⃣️mysql_escape_string(); 方法3⃣️开启魔术引号 ... 
- 浅析word-break work-wrap区别
			word-break:[断词] 定义:规定自动换行的处理方法. 注:通过word-break使用,可以实现让浏览器在任意位置换行. 语法:word-break: normal|break-all| ... 
- JS --- 原型模式
			创建一个对象,先来看一段代码: // 例如创建一个 Person 的构造函数, 让人有名字, 可以说话 function Person ( name ) { this.name = name; // ... 
- div中的内容水平垂直居中
			1. div高度自适应的情况 div在不设置高度的时候,会被里面的内容撑开,内容自动填充在div中,无论是一行内容还是多行内容,此时不需要设置垂直居中,内容自动在中间的, 想要看的更直观些,只需要加上 ... 
- 慕课网__CSS__line height
- 转:C/C++程序员简历模板
			https://github.com/geekcompany/ResumeSample/blob/master/c.md 本简历模板由国内首家互联网人才拍卖网站「 JobDeer.com 」提供. ( ... 
- SQL Server 2012 联机丛书离线安装
			昨日根据微软官网的方式安装SQL Server 2012 联机丛书报错,无法安装: 联机丛书下载位置及安装方式: 按照给出的方式安装,无法完成,错误如下: 
- JS在window和document的应用
			页面跳转: window.location.href('地址') window.open('地址', '_self') 打开新窗口: window.open('地址', '_blank') 只显示地址 ... 
