phpexcel 导出指定大小的图片

set_time_limit(0);
        ini_set(‘memory_limit‘,‘512M‘);
        ini_set(‘max_execution_time‘,0);

        $search[‘doctorname‘] = I(‘get.doctorname‘);
        $search[‘mobile‘] = I(‘get.mobile‘);
        $search[‘state‘] = I(‘get.state‘);
        $search[‘type‘] = I(‘get.type‘);
        $search[‘regclass‘] = I(‘get.regclass‘);
        $search[‘regstarttime‘] = I(‘get.regstarttime‘);
        $search[‘regendtime‘] = I(‘get.regendtime‘);
        $search[‘cstarttime‘] = I(‘get.cstarttime‘);
        $search[‘cendtime‘] = I(‘get.cendtime‘);
        $search[‘prov‘] = I(‘get.prov‘);
        $search[‘city‘] = I(‘get.city‘);
        $search[‘dist‘] = I(‘get.dist‘);
        $search[‘patient_order‘] = I(‘get.patient_order‘);
        $search[‘datacheck‘] = I(‘get.datacheck‘);
        $search[‘remark‘] = I(‘get.remark‘);

        $where = ‘‘;
        if(!empty($search[‘doctorname‘])){
            $where[‘doctor.m_doctorname‘] = [‘LIKE‘, ‘%‘ . $search[‘doctorname‘] . ‘%‘];
        }
        if(!empty($search[‘mobile‘])){
            $where[‘account.u_mobile‘] = [‘LIKE‘, ‘%‘ . $search[‘mobile‘] . ‘%‘];
        }
        if(isset($search[‘state‘]) && strlen($search[‘state‘]) > 0 && $search[‘state‘] >= 0){
            $where[‘account.u_state‘] = $search[‘state‘];
        }
        if(isset($search[‘type‘]) && strlen($search[‘type‘]) > 0){
            if($search[‘type‘] == 3){
                $where[‘doctor.m_type‘] = 0;
                $where[‘doctor.m_doctortechnicalimg‘] = [‘NEQ‘, ‘‘];
            }elseif($search[‘type‘] >= 0){
                $where[‘doctor.m_type‘] = $search[‘type‘];
            }
        }
        if(!empty($search[‘regclass‘]) && $search[‘regclass‘] >= 0){
            $where[‘account.u_reg_class‘] = $search[‘regclass‘];
        }
        if(isset($search[‘datacheck‘]) && strlen($search[‘datacheck‘]) > 0 && $search[‘datacheck‘] >= 0){
            $where[‘doctor.m_datacheck‘] = $search[‘datacheck‘];
        }
        if(!empty($search[‘regstarttime‘]) && empty($search[‘regendtime‘])){
            $where[‘account.u_reg_datetime‘] = [‘gt‘, $search[‘regstarttime‘] . ‘ 00:00:00‘];
        }elseif(empty($search[‘regstarttime‘]) && !empty($search[‘regendtime‘])){
            $where[‘account.u_reg_datetime‘] = [‘lt‘, $search[‘regendtime‘] . ‘ 23:59:59‘];
        }elseif(!empty($search[‘regstarttime‘]) && !empty($search[‘regendtime‘])){
            $where[‘account.u_reg_datetime‘] = [‘BETWEEN‘, [$search[‘regstarttime‘] . ‘ 00:00:00‘, $search[‘regendtime‘] . ‘ 23:59:59‘], ‘and‘];
        }
        if(!empty($search[‘cstarttime‘]) && empty($search[‘cendtime‘])){
            $where[‘account.check_datetime‘] = [‘gt‘, $search[‘cstarttime‘] . ‘ 00:00:00‘];
        }elseif(empty($search[‘cstarttime‘]) && !empty($search[‘cendtime‘])){
            $where[‘account.check_datetime‘] = [‘lt‘, $search[‘cendtime‘] . ‘ 23:59:59‘];
        }elseif(!empty($search[‘cstarttime‘]) && !empty($search[‘cendtime‘])){
            $where[‘account.check_datetime‘] = [[‘gt‘, $search[‘cstarttime‘] . ‘ 00:00:00‘], [‘lt‘, $search[‘cendtime‘] . ‘ 23:59:59‘], ‘and‘];
        }
        if(!empty($search[‘prov‘])){
            $where[‘doctor.m_hdistrict‘] = [‘LIKE‘, ‘%‘ . trim($search[‘prov‘] . ‘ ‘ . $search[‘city‘] . ‘ ‘ . $search[‘dist‘]) . ‘%‘];
        }
        if(!empty($search[‘remark‘]) && $search[‘remark‘] >= 0){
            if($search[‘remark‘] == 1){
                $where[‘doctor.m_remarks‘] = [‘NEQ‘, ‘‘];
            }else{
                $where[‘doctor.m_remarks‘] = [‘EQ‘, ‘‘];
            }
        }

        $doctor = new DoctorModel(‘‘, ‘‘, C(‘MAMI_ADMIN_DB_MYCAT‘));

        $data = $doctor->getDoctorList($where,$field="doctor.u_id,doctor.m_doctorname,doctor.m_sex,account.u_mobile,doctor.m_hdistrict,doctor.m_hname,doctor.m_dname,doctor.m_technicalname,doctor.createdatetime,account.check_datetime,doctor.m_remarks,doctor.d_extend,doctor.m_type");
//        echo $data;exit;
        Vendor(‘phpexcel.PHPExcel‘);
        //新建
        $resultPHPExcel = new \PHPExcel();
        $datatype = new \PHPExcel_Cell_DataType();
        $PHPExcel_Style_Alignment = new \PHPExcel_Style_Alignment();
        $PHPExcel_Style_Alignment =  new \PHPExcel_Style_Alignment();
        $PHPExcel_Style_Border = new \PHPExcel_Style_Border();
        $PHPExcel_IOFactory = new \PHPExcel_IOFactory();

        $PHPExcel_CachedObjectStorageFactory = new \PHPExcel_CachedObjectStorageFactory();
        $PHPExcel_Settings = new \PHPExcel_Settings();

        $cacheMethod = $PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
        $cacheSettings = array();
        $PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);

        //设置参数
        //设值
        $resultPHPExcel->getActiveSheet()->setCellValue(‘A1‘, ‘编号‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘B1‘, ‘医生姓名‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘C1‘, ‘性别‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘D1‘, ‘手机号‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘E1‘, ‘省市区‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘F1‘, ‘所属医院‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘G1‘, ‘科室‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘H1‘, ‘职称‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘I1‘, ‘创建时间‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘J1‘, ‘审核时间‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘K1‘, ‘维护‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘L1‘, ‘资质‘);
        $resultPHPExcel->getActiveSheet()->setCellValue(‘M1‘, ‘二维码‘);

        //垂直/水平居中
        $resultPHPExcel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $resultPHPExcel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        $sex = array(‘女‘, ‘男‘);
        $tarr = array(‘未认证‘,‘认证‘,‘认证未通过‘);
        $i = 2;
        foreach ($data as $key =>&$item) {
            $d = json_decode($item[‘d_extend‘],JSON_UNESCAPED_UNICODE);
            $img = $d[‘wx_ewm‘];
            $d[‘wx_ewm‘] = ‘‘;
            $item[‘m_type‘] = $tarr[$item[‘m_type‘]];
            if(!empty($item[‘remarks‘])){
                $item[‘remarks‘] = ‘已维护‘;
            }else{
                $item[‘remarks‘] = ‘未维护‘;
            }
            $newim = imagecreate (150, 150);
            $img = imagecreatefromjpeg($img);
            $width = imagesx($img);
            $height = imagesy($img);
            imagecopyresized($newim,$img,0,0,0,0,150,150,$width,$height);

            $objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
            $resultPHPExcel->getActiveSheet()->setCellValueExplicit(‘A‘ . $i, $item[‘u_id‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘B‘ . $i, $item[‘m_doctorname‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘C‘ . $i, $sex[$item[‘m_sex‘]]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘D‘ . $i, $item[‘u_mobile‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘E‘ . $i, $item[‘m_hdistrict‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘F‘ . $i, $item[‘m_hname‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘G‘ . $i, $item[‘m_dname‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘H‘ . $i, $item[‘m_technicalname‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘I‘ . $i, $item[‘createdatetime‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘J‘ . $i, $item[‘check_datetime‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘K‘ . $i, $item[‘remarks‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘L‘ . $i, $item[‘m_type‘]);
            $resultPHPExcel->getActiveSheet()->setCellValue(‘M‘ . $i, $d[‘wx_ewm‘]);

            $resultPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);

            $objDrawing->setName(‘erweima‘);

            $objDrawing->setDescription(‘erweima‘);

            $objDrawing->setCoordinates(‘M‘.$i);

            $objDrawing->setImageResource($newim);

            $objDrawing->setOffsetX(10);

            $objDrawing->setOffsetY(10);

            $objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);

            $objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);

            $resultPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(130);

            $objDrawing->setWorksheet($resultPHPExcel->getSheet());

            $i++;
        }

        //设置表格宽度
        $resultPHPExcel->getActiveSheet()->getColumnDimension(‘C‘)->setWidth(25);

        //垂直/水平居中
        $resultPHPExcel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal($PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $resultPHPExcel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical($PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        //设置导出文件名
        $obj_Writer = $PHPExcel_IOFactory->createWriter($resultPHPExcel, ‘Excel5‘);
        $filename = "医生数据统计表.xls";
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header(‘Content-Disposition:inline;filename="‘ . $filename . ‘"‘);
        header("Content-Transfer-Encoding: binary");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        $obj_Writer->save(‘php://output‘);

里面有如何将网络上的图片修改成指定大小,并导入phpexcel中

时间: 2024-10-31 01:41:14

phpexcel 导出指定大小的图片的相关文章

PHP 生成指定大小随机图片

PHP 生成指定大小随机图片 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 <?php $image_width = 100; $image_height = 100; $image_str = ''; if (isset($_GET[

C# 压缩图片到指定宽度,假如图片小于指定宽度 判断图片大小是否大于指定大小(KB) 如果大于则压缩图片质量 宽高不变

class Program { static void Main(string[] args) {//G:\zhyue\backup\projects\Test\ConsoleApplication1\img //var url = "http://seo.jrechina.com/houselist/"; //var res = WebRequestExt.GetData(url); string img_url = @"D:\Documents\Pictures\壁纸\1

phpExcel导出excel加超级链接的实例代码[转]

phpexcel实现的导出excel文件的代码,且可以在excel文件中加入超级链接. 说明:PHPExcel的开发包Tests目录有详细使用实例.以下代码支持中文,注意文件编码,文件保存为utf-8. 完整代码: 代码示例: <?php//写excel //Include class require_once(‘Classes/PHPExcel.php’); require_once(‘Classes/PHPExcel/Writer/Excel2007.php’); $objPHPExcel

PHPExcel导出excel

如果导出中文时出现乱码,可以尝试将字符串转换成gb2312,例如下面就把$yourStr从utf-8转换成了gb2312: $yourStr = mb_convert_encoding("gb2312", "UTF-8", $yourStr); 总结 php导出Excel php导入Excel PhpExcel使用说明 PhpExcel使用手册 1:第一推荐无比风骚的PHPExcel,官方网站: http://www.codeplex.com/PHPExcel 导入

【Android】自定义圆形ImageView(圆形头像 可指定大小)

最近在仿手Q的UI,这里面经常要用到的就是圆形头像,看到 在android中画圆形图片的几种办法 这篇文章,了解了制作这种头像的原理.不过里面提供的方法还有一个不足的地方就是不能根据实际需求改变图片的大小,也就是说提供的原图是大尺寸的,转换之后的图片也是大尺寸的,这显然不符合我们实际项目中的需求.于是我对里面介绍的第一种方法做了一番改进,使其能直接在XML中指定图片的大小. 大体步骤 将原图居中裁剪成正方形 根据指定的宽度对正方形进行缩放 裁剪成圆形 效果 代码实现 package com.de

减小App大小:图片篇

App大小是受产品经理关注的,因为部分用户会由于下载时间.流量耗费等而倾向于较小的app,这点尤其在网络速度较差或资费较贵的国家比较明显,比如印度. 有不少的app,其中占空间最大的是资源文件,通常是图片. 我们最近的一个app就比较关注图片资源的大小,并有了以下几点的经验,包括iOS和Android. 1. 不用图片实现 有些简单的图形,是可以通过一些简单的编程做出来的,比如分割线.四周圆角. 在iOS里,一些简单的折线用Bezier Path也可以很容易的画出来的. 当然这里要有个限度,太复

【Android】自己定义圆形ImageView(圆形头像 可指定大小)

近期在仿手Q的UI,这里面常常要用到的就是圆形头像,看到 在android中画圆形图片的几种办法 这篇文章,了解了制作这样的头像的原理.只是里面提供的方法另一个不足的地方就是不能依据实际需求改变图片的大小,也就是说提供的原图是大尺寸的,转换之后的图片也是大尺寸的,这显然不符合我们实际项目中的需求.于是我对里面介绍的第一种方法做了一番改进,使其能直接在XML中指定图片的大小. 大体步骤 将原图居中裁剪成正方形 依据指定的宽度对正方形进行缩放 裁剪成圆形 效果 代码实现 package com.de

未知大小的图片居中

未知大小的图片在指定大小的div盒子中垂直水平居中: <style> .box { /*垂直居中*/ display: table-cell; vertical-align:middle; /*水平居中*/ text-align:center; /* IE */ *display: block; *font-size: 175px;/*约为高度的0.873,200*0.873 约为175*/ *font-family:Arial;/*防止非utf-8引起的hack失效问题,如gbk编码*/ w

android 裁剪图片大小 控制图片尺寸

用BitmapFactory获取适合屏幕大小的图片 和自带的图片裁剪工具 package com.lin.image; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import an