简体   繁体   中英

Read URL from excel file using Spreadsheet_Excel_Reader in php

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM