php - 如何在 phpexcel 中编写连接 url nd 文本
问题描述
我正在打印一些在phpexcel中动态的url
$sheet->setCellValue('M'.($results+2),($result['headline']).$result['url']);
但输出是这样的Govt to start Air India roadshows in Singapore this weekhttp://www.windowtonews.com/news.php?id=288115
我怎么写才能使链接出现在带有超链接的文本上
解决方案
你可以通过三个步骤来做到这一点:
- 设置单元格值
- 将此单元格的数据类型设置为
string2
- 设置此文本值的 url 链接
$sheet->setCellValue('M'.($results+2),$result['headline']);
$sheet->getCell('M'.($results+2))->setDataType(PHPExcel_Cell_DataType::TYPE_STRING2);
$sheet->getCell('M'.($results+2))->getHyperlink()->setUrl(strip_tags($result['url']));
在一行中,它看起来像:
$sheet->setCellValueExplicit('M'.($results+2), $result['headline'], PHPExcel_Cell_DataType::TYPE_STRING2, TRUE)
->getHyperlink()
->setUrl(strip_tags($result['url']));
setCellValueExplicit() - 类似于 getCell(),如果设置为true
返回单元格而不是工作表(类似于 getActiveSheet())。
推荐阅读
- .net - 使用 .NET 和 powershell 验证 RSA 签名
- python - pysimplegui - 用于一直向下滚动的按钮
- c# - NSubstitute 返回空字符串
- node.js - 如何在不将转换后的文件存储到文件夹的情况下从 FFMPEG 获取转换后的文件
- javascript - NEST JS 模块注册错误与新连接
- python-3.x - 在 Python Azure 函数中,如何仅用一行代码在函数中导入共享库?
- python - 如何在python中使用findAll()函数
- vim - in vim how can you insert the current date/time into a note
- css - 覆盖来自 node_modules next.js 的全局 css
- python - 提示用户