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:不同的数据源, ...
随机推荐
- "rel=nofollow"属性
nofollow是HTML元标签(meta)的content属性和链接标签(a)的rel属性的一个值,告诉机器(爬虫)无需追踪目标页,为了对抗blogspam(博客垃圾留言信息),Google推荐使用 ...
- linux搭建LAMP
先简要概述下本文要点:(操作系统采用CentOS6.5 x64) 1.分别安装搭建lamp服务环境: 2.采用lamp一键安装包搭建环境: 3.在lamp环境中初步搭建起一个网站: 一. 分别安装搭建 ...
- [Android] keystore生成
keytool -genkey -alias agg_keystore -keyalg RSA -validity 20000 -keystore agg.keystore keytool -expo ...
- PHP Mysqli 数据库连接
---恢复内容开始--- $connection=new mysqli($db_host,$db_user,$db_password,$db_name);if(!mysqli_connect_errn ...
- miniui
//android提供了一个库minui用于简单的UI输出,源码在bootable/recovery/minui中, //gr_init()和gr_font_size()为minui库提供方法,gr_ ...
- mybatis入门_配置文件的配置
一.全局配置文件配置 1.1 properties标签 Properties标签可以用来加载配置文件.例如,我们可以将数据库的连接信息放入到一个配置文件(db.properties中..) 下为db. ...
- 【算法】Hough变换
终于看懂点了霍夫变换,以下内容来源为吉大的硕士论文,作者王阳阳 上图引用自 http://www.cnblogs.com/Ponys/p/3146753.html
- Software Engineering: 3. Project planning
recourse: "Software Engineering", Ian Sommerville Keywords for this chapter: planning sche ...
- Apache Commons Collections
http://commons.apache.org/proper/commons-collections/userguide.html 1. Utilities SetUtils Collection ...
- InventSumDelta表的作用
https://groups.google.com/forum/#!topic/microsoft.public.axapta.programming/rRfbJo9M0dk The purpose ...