Issue
I am printing some url which is coming dynamic in phpexcel
$sheet->setCellValue('M'.($results+2),($result['headline']).$result['url']);
but the output is like this Govt to start Air India roadshows in Singapore this weekhttp://www.windowtonews.com/news.php?id=288115
How can i write so that link comes on text with hyperlink
Solution
You could do this in three steps:
- set cell value
- set datatype of this cell to
string2
- set url link to this text value
$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']));
In one line it would looks like:
$sheet->setCellValueExplicit('M'.($results+2), $result['headline'], PHPExcel_Cell_DataType::TYPE_STRING2, TRUE)
->getHyperlink()
->setUrl(strip_tags($result['url']));
setCellValueExplicit() - similar to getCell(), if setted to true
returns the cell instead of the sheet (similar to getActiveSheet()).
Answered By - Aksen P Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.