dongquexi1990 2016-04-13 12:22
浏览 103
已采纳

使用php中的Spreadsheet_Excel_Reader从excel文件中读取URL

I am using Spreadsheet_Excel_Reader() to read a excel file.

I want to read a url in sheet data like below

<a href="link">text</a>

I know this problem will solve by using PHPExcel like this

$leadCommentLInk=$worksheet->getCellByColumnAndRow(7, 2)->getHyperlink()->getUrl();

please help me in this

  • 写回答

1条回答 默认 最新

  • dongxindu8753 2016-04-14 06:15
    关注

    Finally I got the solution by changing my reader.php file like this

    Added following switch case in _parsesheet method

    case SPREADSHEET_EXCEL_READER_TYPE_HYPER:
                    //  Only handle hyperlinks to a URL
                    $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
                    $row2   = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
                    $column = ord($this->data[$spos+4]) | ord($this->data[$spos+5])<<8;
                    $column2 = ord($this->data[$spos+6]) | ord($this->data[$spos+7])<<8;
                    $linkdata = Array();
                    $flags = ord($this->data[$spos + 28]);
                    $udesc = "";
                    $ulink = "";
                    $uloc = 32;
                    $linkdata['flags'] = $flags;
                    if (($flags & 1) > 0 ) {   // is a type we understand
                        //  is there a description ?
                        if (($flags & 0x14) == 0x14 ) {   // has a description
                            $uloc += 4;
                            $descLen = ord($this->data[$spos + 32]) | ord($this->data[$spos + 33]) << 8;
                            $udesc = substr($this->data, $spos + $uloc, $descLen * 2);
                            $uloc += 2 * $descLen;
                        }
                        $ulink = $this->read16bitstring($this->data, $spos + $uloc + 20);
                        if ($udesc == "") {
                            $udesc = $ulink;
                        }
                    }
                    $linkdata['desc'] = $udesc;
                    $linkdata['link'] = $this->_encodeUTF16($ulink);
                    for ($r=$row; $r<=$row2; $r++) { 
                        for ($c=$column; $c<=$column2; $c++) {
                            $this->sheets[$this->sn]['cellsInfo'][$r+1][$c+1]['hyperlink'] = $linkdata;
                        }
                    }
                    break;
    

    and add this constant

    define('SPREADSHEET_EXCEL_READER_TYPE_HYPER',        0x01b8);
    

    and mothod

    function read16bitstring($data, $start) {
        $len = 0;
        while (ord($data[$start + $len]) + ord($data[$start + $len + 1]) > 0) $len++;
        return substr($data, $start, $len);
    }
    

    or else we can simply use one file excel_reader2.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器