PHPExcel 向单元格插入图片就换行的问题
要用phpexcel从数据库中将表导出为excel格式,表中存放有图片路径现在我的代码如下:
1 |
|
导出的excel如下
请教下 要把图片的路径换成真实的图片输出代码该怎么修改? 还有怎么让excel的标题分成两行显示并加粗,代码该如何修改?
回复讨论(解决方案)
图片如下
标题换行只需在需要换行的地方加上换行符
比如 "Product \ncode"
其他的明天说
标题换行只需在需要换行的地方加上换行符
比如 "Product \ncode"
其他的明天说
1 |
|
/n \n都试过了...都不行。
加粗 范例
$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
添加图片 范例
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('./images/officelogo.jpg');
$objDrawing->setHeight(36);
$objDrawing->setCoordinates('B15');
$objDrawing->setOffsetX(110);
$objDrawing->setRotation(25);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
加粗 范例
$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
添加图片 范例
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('./images/officelogo.jpg');
$objDrawing->setHeight(36);
$objDrawing->setCoordinates('B15');
$objDrawing->setOffsetX(110);
$objDrawing->setRotation(25);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
插入图片的代码该加到哪儿呢?我这样加不对
1 |
|
$objDrawing = new PHPExcel_Worksheet_Drawing();
要放在循环内,即每个图片需要一个 PHPExcel_Worksheet_Drawing 实例
setHeight 图片高
setCoordinates 所在单元格
setOffsetX 左上角相对单元格的x偏移
setRotation 旋转角
更多的方法请见文档
$objDrawing = new PHPExcel_Worksheet_Drawing();
要放在循环内,即每个图片需要一个 PHPExcel_Worksheet_Drawing 实例
setHeight 图片高
setCoordinates 所在单元格
setOffsetX 左上角相对单元格的x偏移
setRotation 旋转角
更多的方法请见文档
导出来了,只是位置不对,要把图片设置到单元格里代码该怎么修改?
我 setCoordinates('B15') (15行B列)
你也在 setCoordinates('B15') 吗?
我 setCoordinates('B15') (15行B列)
你也在 setCoordinates('B15') 吗?
果然这样,但又有个问题,我把图片设置到了图片名称出现的位置。
1 |
|
出来效果是这样的
图片只是出现在单元格的位置,并不是单元格的值
要达到下面的效果该怎么设置单元格?
不是说了吗?
$objDrawing->setOffsetX(80); //表示图片左边距是 80
$objDrawing->setRotation(25); //表示旋转 25 度
显然都不是你需要的
你只需设置单元格居中排列
批量设置,我一般用 PHPExcel_Style 来写,如
1 |
|
当然一个个的设置也是没有问题的
不是说了吗?
$objDrawing->setOffsetX(80); //表示图片左边距是 80
$objDrawing->setRotation(25); //表示旋转 25 度
显然都不是你需要的
你只需设置单元格居中排列
批量设置,我一般用 PHPExcel_Style 来写,如
1 |
|
当然一个个的设置也是没有问题的
格式搞定了 现在就剩两个问题了:
1、导出图片到cell里面。
2、页面上有导出excel按钮,怎么通过点击按钮,将页面的参数传到后台(前台页面不跳转)以导出对应的excel。
大师把这个分数一起拿走吧 小弟分数不多... http://bbs.csdn.net/topics/390730241
1、导出图片上面已经说了,你也做到了。只是要注意调整格式
2、导出excel按钮可以是表单的提交按钮,设置表单的 target 指向一个隐藏的 iframe 就不会跳转了
1 |
|
1、导出图片上面已经说了,你也做到了。只是要注意调整格式
2、导出excel按钮可以是表单的提交按钮,设置表单的 target 指向一个隐藏的 iframe 就不会跳转了
1 |
|
大师 再请教个问题,向excel中写入图片时,当图片不存在,phpexcel会抛出异常不能形成excel文件,于是我捕获异常(被注释掉的代码)
1 |
|
这样就算图片不存在也能导出excel,但导出的excel就是打不开,请问如何解决?
1 |
|
1 |
|
请问大师 输出pdf文档该怎么输出呢?
我这样输出文件很小很小,而且打不开
1 |
|
我没做过,刚才试了一下
不但样式难看,而且不能显示中文

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
