function excel_down(){
//导入谁就去查谁
$data=Db::name('order_xueyou')->select(); // 导出Exl
// import("./PHPExcel");
// import("./PHPExcel/Worksheet/Drawing");
// import("./PHPExcel/Writer/Excel2007");
include("./PHPExcel/PHPExcel.php");
include("./PHPExcel/Drawing.php"); $objPHPExcel = new \PHPExcel(); $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel); $objActSheet = $objPHPExcel->getActiveSheet(); // 水平居中(位置很重要,建议在最初始位置)
$objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('K')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('L')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('M')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('N')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('O')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('P')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('Q')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('R')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('S')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('T')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('U')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('V')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('W')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('X')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('Y')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objActSheet->setCellValue('A1', 'id');
$objActSheet->setCellValue('B1', 'openid');
$objActSheet->setCellValue('C1', 'nickName');
$objActSheet->setCellValue('D1', 'buyer');
$objActSheet->setCellValue('E1', 'ordertime');
$objActSheet->setCellValue('F1', 'orderdate');
$objActSheet->setCellValue('G1', 'address');
$objActSheet->setCellValue('H1', 'name');
$objActSheet->setCellValue('I1', 'goodid');
$objActSheet->setCellValue('J1', 'img');
$objActSheet->setCellValue('K1', 'oneprice');
$objActSheet->setCellValue('L1', 'num');
$objActSheet->setCellValue('M1', 'color');
$objActSheet->setCellValue('N1', 'sex');
$objActSheet->setCellValue('O1', 'size');
$objActSheet->setCellValue('P1', 'buynum');
$objActSheet->setCellValue('Q1', 'buy');
$objActSheet->setCellValue('R1', 'price');
$objActSheet->setCellValue('S1', 'status');
$objActSheet->setCellValue('T1', 'formkorea');
$objActSheet->setCellValue('U1', 'saddress');
$objActSheet->setCellValue('V1', 'remark');
$objActSheet->setCellValue('W1', 'formchina');
$objActSheet->setCellValue('X1', 'subremark');
$objActSheet->setCellValue('Y1', 'ddh');
// 设置个表格宽度
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(16);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setWidth(12); // 垂直居中
$objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('K')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('L')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('M')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('N')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('O')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('P')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('Q')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('R')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('S')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('T')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('U')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('V')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('W')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('X')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('Y')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); foreach($data as $k=>$v){
$k +=2;
$objActSheet->setCellValue('A'.$k, $v['id']);
$objActSheet->setCellValue('B'.$k, $v['openid']);
$objActSheet->setCellValue('C'.$k, $v['nickName']);
$objActSheet->setCellValue('D'.$k, $v['buyer']);
$objActSheet->setCellValue('E'.$k, $v['ordertime']);
$objActSheet->setCellValue('F'.$k, $v['orderdate']);
$objActSheet->setCellValue('G'.$k, $v['address']);
$objActSheet->setCellValue('H'.$k, $v['name']);
$objActSheet->setCellValue('I'.$k, $v['goodid']); //获取到图片信息
$img = Db::name('order_xueyou')->where('id = '.$v['id'])->field('img')->find();
//dump($img);
// die();
// 图片生成
$objDrawing[$k] = new \PHPExcel_Worksheet_Drawing();
$objDrawing[$k]->setPath('.'.$img['img']);//这里拼接 . 是因为要在根目录下获取
// 设置宽度高度
$objDrawing[$k]->setHeight(80);//照片高度
$objDrawing[$k]->setWidth(80); //照片宽度
/*设置图片要插入的单元格*/
$objDrawing[$k]->setCoordinates('J'.$k);
// 图片偏移距离
$objDrawing[$k]->setOffsetX(12);
$objDrawing[$k]->setOffsetY(12);
$objDrawing[$k]->setWorksheet($objPHPExcel->getActiveSheet()); // 表格内容
$objActSheet->setCellValue('K'.$k, $v['oneprice']);
$objActSheet->setCellValue('L'.$k, $v['num']);
$objActSheet->setCellValue('M'.$k, $v['color']);
$objActSheet->setCellValue('N'.$k, $v['sex']);
$objActSheet->setCellValue('O'.$k, $v['size']);
$objActSheet->setCellValue('P'.$k, $v['buynum']);
$objActSheet->setCellValue('Q'.$k, $v['buy']);
$objActSheet->setCellValue('R'.$k, $v['price']);
$objActSheet->setCellValue('S'.$k, $v['status']);
$objActSheet->setCellValue('T'.$k, $v['formkorea']);
$objActSheet->setCellValue('U'.$k, $v['saddress']);
$objActSheet->setCellValue('V'.$k, $v['remark']);
$objActSheet->setCellValue('W'.$k, $v['formchina']);
$objActSheet->setCellValue('X'.$k, $v['subremark']);
$objActSheet->setCellValue('Y'.$k, $v['ddh']); // 表格高度
$objActSheet->getRowDimension($k)->setRowHeight(80); } $fileName = '报价表';
$date = date("Y-m-d",time());
$fileName .= "_{$date}.xls";
$fileName = iconv("utf-8", "gb2312", $fileName);
//重命名表
// $objPHPExcel->getActiveSheet()->setTitle('test');
//设置活动单指数到第一个表,所以Excel打开这是第一个表
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=\"$fileName\"");
header('Cache-Control: max-age=0');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output'); //文件通过浏览器下载
// END
}

tp5 数据库信息导出到excel(带图片)的更多相关文章

  1. Python实现数据库一键导出为Excel表格

    依赖 Python2711 xlwt MySQLdb 数据库相关 连接 获取字段信息 获取数据 Excel基础 workbook sheet 案例 封装 封装之后 测试结果 总结 数据库数据导出为ex ...

  2. itext poi 学习之旅 (3)读取数据库信息并由excel展现出来

    DBConnection.java 连接数据库操作 package com.zkbj.poi; import java.sql.Connection; import java.sql.DriverMa ...

  3. Java利用Apache POI将数据库数据导出为excel

    将数据库中的数据导出为excel文件,供其他人查看 public class POITest { public static void main(String[] args) { POITest te ...

  4. Java:将数据库数据导出到Excel (一眼就看会)

    所用Jar包 1. sqljdbc4.jar 连接数据库的Jar包(根据数据库的不同进行选择,我用的SqlServer2008) 2.Jxl.jar 访问Excel的Jar包 注意:支持以.xls结尾 ...

  5. Java实现将Excel导入数据库和从数据库中导出为Excel

    实现的功能: 用Java实现从Excel导入数据库,如果存在就更新 将数据库中的数据导出为Excel 1.添加jxl.jar mysql-connector-java.1.7-bin.jar包到项目的 ...

  6. PCB MS SERVER 使用bcp命令将数据库数据导出到Excel

    在前年工程系统与APS系统对接时,需将工程系统数据导出来给APS,采用的正是bcp命令实现,速度超快. 这里将此命令使用方法整理如下: 一.写SQL将表数据导出到Excel @echo "& ...

  7. NPOI 导出excel带图片,可控大小

    using NPOI.HSSF.UserModel;using NPOI.HSSF.Util;using NPOI.DDF;using NPOI.SS.UserModel;using System.I ...

  8. asp.net 导出excel带图片

    protected void btgua_Click(object sender, EventArgs e) { DataTable dt = ds.Tables[0]; if (dt != null ...

  9. PowerDesigner数据库设计导出到Excel

    在PowerDesigner 中 ctrl+shift+x 弹出执行脚本界面,输入如下代码就会生成 Excel   Option Explicit Dim rowsNum rowsNum = '--- ...

随机推荐

  1. 关于String s = new String("xyz");创建了几个字符串对象?的问题

    引用自这位朋友:http://blog.sina.com.cn/s/blog_6a6b14100100zn6r.html 首先让我们了解几个概念: 栈:由JVM分配区域,用于保存线程执行的动作和数据引 ...

  2. 基于VB语言对SolidWorks参数化设计的二次开发

    0 引言 随着数字信息化进程的快速推进,如今三维CAD技术在越来越多的企业当中得到运用.为了降低在设计生产中的成本,缩短设计周期,增强企业竞争力,三维参数化技术随之应声,它凭借更贴近现代概念的设计以及 ...

  3. 极点五笔词库DIY

    2004年没啥好的拼音输入法,试了清华紫光输入法一段时间,也相当不满意, 于是在2005年开始学五笔,很快就选定极点五笔了, 使用过程中没啥不满意的,反而还有惊喜: 重装系统后,双击就安装好输入法了, ...

  4. 3.Zabbix 3.0 部署

    请查看我的有道云笔记: http://note.youdao.com/noteshare?id=0139b8d2833129740be82e36a94e4fca&sub=5931260FCC8 ...

  5. Oracle 11.1.0.6 导入导出bug

    实验环境: 11.1.0.6.0   对ANONYMOUSUSER_ALL表中分区进行备份 SQL> select TABLE_NAME,PARTITION_NAME,HIGH_VALUE,PA ...

  6. Android(java)学习笔记40:WindowManager 中LayoutParams的各种属性

    1. WindowManager 中LayoutParams的各种属性 WindowManager.LayoutParams 是 WindowManager 接口的嵌套类(内部类):它继承于 View ...

  7. Mac下更新Vim到最新版本

    目前,Mac内置的Vim是7.3版本的,而且还缺少很多功能,下面介绍如何通过源码安装更新最新版本的Vim,同时保留系统内置的Vim. # 下载Vim源代码 git clone https://gith ...

  8. java中String、StringBuffer和StringBuilder的区别(简单介绍)

    简单介绍 java中用于处理字符串常用的有三个类: 1.java.lang.String 2.java.lang.StringBuffer 3.java.lang.StrungBuilder 三者共同 ...

  9. Android学习笔记_66_图片处理专题

    1.图片缩放:不解析整个图片信息. public class DemoActivity extends Activity { @Override public void onCreate(Bundle ...

  10. java基础知识一览

    一.关键字:JDK1.5的新特性.Eclipse.MyEclipse.IDE.Workspace.Perspective.view.设置javac和java的版本.模块代码.快捷键.导入工程.静态导入 ...