读取超链接URL

时间:2011-04-28 21:08:37

标签: php phpexcel

如何使用PHPExcel读取单元格内超链接的URL?

2 个答案:

答案 0 :(得分:18)

$url = $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->getUrl();

修改

您可能想要先测试单元格是否有超链接

$objPHPExcel->getActiveSheet()->getCell('E26')->hasHyperlink();

编辑2

请注意,setReadDataOnly(true)

时不会加载超链接

答案 1 :(得分:0)

<?php

    require 'vendor/autoload.php';

    use PhpOffice\PhpSpreadsheet\Spreadsheet;
    use PhpOffice\PhpSpreadsheet\Reader\Xlsx;

    $reader = new Xlsx();

    $spreadsheet = $reader->load("test.xlsx");

    $sheetData = $spreadsheet->getActiveSheet()->getCell('B7')->getHyperlink()->getUrl();

    print_r($sheetData);
?>