Writing Images to the Excel Sheet using PHPExcel--转载
原文地址:http://www.walkswithme.net/writing-images-to-the-excel-sheet-using-phpexcel
Writing images to the excel sheet using phpexcel class is a great feature , using this method we can draw the images inside the excel column it looks good and nice to have images with some descriptions.
While working on an Import/Export system I have noticed this facility of PHPExcel its really good and easy, Ok lets check the code for writing images to the excel sheet using PHPExcel.
include 'PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("Jobin Jose");
$objPHPExcel->getProperties()->setLastModifiedBy("Jobin Jose");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHPExcel classes.");
// Add some data
// echo date('H:i:s') . " Add some data\n";
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!');
//$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!');
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$gdImage = imagecreatefromjpeg('uploads/t12.jpg');
// Add a drawing to the worksheetecho date('H:i:s') . " Add a drawing to the worksheet\n";
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('C1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
The out put will be like as follows.
Writing Images to Excel Using PHPExcel
The above code will create an “xlsx” formatted file because it uses 2007 excel classes If you want “xls” format just try with 2005 class do not for get to change the file format to “xls” while using 2005.
Writing Images to the Excel Sheet using PHPExcel--转载的更多相关文章
- [LeetCode] Excel Sheet Column Number 求Excel表列序号
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- [LeetCode] Excel Sheet Column Title 求Excel表列名称
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
- Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number
题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...
- ✡ leetcode 171. Excel Sheet Column Number 字母转换为数字 --------- java
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- LeetCode 168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet. -> A ...
- 【leetcode】Excel Sheet Column Title
Excel Sheet Column Title Given a non-zero positive integer, return its corresponding column title as ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number (easy)
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
- LeetCode 171 Excel Sheet Column Number
Problem: Given a column title as appear in an Excel sheet, return its corresponding column number. F ...
随机推荐
- [COI2007] Patrik 音乐会的等待 单调栈
Code: #include<cstdio> #include<algorithm> #include<iostream> #include<cstring& ...
- 我的头上碧空晴朗——数据库存datetime问题
今天遇到一个问题,数据库mysql存的datetime类型数据.取出来数据居然耍流氓,好好的日期在秒后多了个小数点0 当我用正常的方法, SimpleDateFormat myFmt=new Simp ...
- 多路I/O转接之select模型
I/O复用使得程序可以同一时候监听多个文件描写叙述符.这对提高程序的性能至关重要.通常,网络程序同一时候处理或者监听多个socket文件描写叙述符的时候可以考虑使用I/O复用模型. 值得强调的是.I/ ...
- ios—项目开发需求文档
电子商务产品项目需求方案 模块 标准 接入方式 后台(大致需求说明) 前端 购 实物 多商户接入,可支付商品: 基础功能 功能说明 所有须要 Lbs .城市选择,分享.商区.搜索.返回.关闭 LBS: ...
- php 图片局部打马赛克
php 图片局部打马赛克 原理: 对图片中选定区域的每一像素,添加若干宽度及高度,生成矩型.而每一像素的矩型重叠在一起.就形成了马赛克效果. 本例使用GD库的imagecolorat获取像素颜色,使用 ...
- vue 打包成 apk 文件(修改路径)
第一个坑:文件引用路径 现在项目我们什么都没动,是初始化之后直接打包的状态,打开dist/index.htmnl文件整个网页都是一片空白的. 爬坑: 打开 config文件夹/index.js文件 a ...
- java为什么要定义接口等相关解释
1.接口的作用是实现多重继承 因为只能继承一个类(规定的) 2.一个类只能继承一个父类,但是可以实现一个或多个接口 3.abstract关键词能让你在类里创建一个或多个没有定义的方法—你给出接口,但 ...
- java判断编码格式
package com.sssjd.storm; import java.io.UnsupportedEncodingException; /** * Created by jorda on 2017 ...
- google dataflow model 论文
http://www.chinacloud.cn/show.aspx?id=24446&cid=17
- 【Codeforces Round #426 (Div. 2) C】The Meaningless Game
[Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...