PHPExcel-如何设置网址 [英] PHPExcel - How to set a url

查看:80
本文介绍了PHPExcel-如何设置网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是isung PHPExcel,并且在字符串中有一个URL. 做的时候:

I am isung PHPExcel and have a URL in a string. When doing:

$url = 'http://dx.doi.org/10.1016/j.phymed.2005.11.003'
$xls = new PHPExcel();
$xls->setActiveSheetIndex(0);
$xls->getActiveSheet()->setCellValueByColumnAndRow(1,2,$url);

该网址设置为简单文本.

The url is set as simple text.

我也尝试过:

$xls->getActiveSheet()->getCellByColumnAndRow(1,2)->getHyperlink()->setUrl('"'.$url.'"');

但是,当单击链接时,它将尝试打开本地文件夹.

But then, when clicking on the link, it tries to open a local folder.

有什么想法吗?

谢谢.

编辑

当我尝试这样做时,请不要使用引号:

When I try do do this without quotes:

$xls->getActiveSheet()->getCellByColumnAndRow(1,2)->getHyperlink()->setUrl($url);

然后我得到了错误:

Exception' with message 'Invalid parameters passed.'

我的真实网址是

http://dx.doi.org/10.1016/j.phymed.2005.11.003

我注意到,当在末尾设置斜杠时,超链接有效,但是URL错误.

I noticed that when setting a slash at the end, the hyperlink works, but the url is then wrong.

推荐答案

我找到了解决方案,以某种方式我的url无法被excel识别.

I have found the solution, somehow the url I had was not recognized by excel.

$url = str_replace('http://', '', $link);
$xls->getActiveSheet()->getCellByColumnAndRow(1,2)->getHyperlink()->setUrl('http://www.'.$url);

现在它可以工作了.希望这会有所帮助.

And now it works. Hope this will help.

这篇关于PHPExcel-如何设置网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆