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 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页