PHPExcel - How to set a url

前端 未结 4 789
Happy的楠姐
Happy的楠姐 2021-02-04 06:53

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->setActiveSh         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 06:53

    I am guessing your field value has integer value. If it is so, then you first have to convert the data type of that cell and then set the hyperlink. Below is how I have done this.

    //set the value of the cell
    $this->phpExcelObj->getActiveSheet()->SetCellValue('A1',$id);
    //change the data type of the cell
    $this->phpExcelObj->getActiveSheet()->getCell("A1")->setDataType(PHPExcel_Cell_DataType::TYPE_STRING2);
    ///now set the link
    $this->phpExcelObj->getActiveSheet()->getCell("A1")->getHyperlink()->setUrl(strip_tags($link));
    

提交回复
热议问题