How to write Concatenate url nd text in phpexcel

281 Views Asked by At

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

1

There are 1 best solutions below

0
Aksen P On BEST ANSWER

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()).