⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
    */    function _convertRange2d($range)    {        $class = 2; // as far as I know, this is magick.        // Split the range into 2 cell refs        if (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/", $range)) {            list($cell1, $cell2) = split(':', $range);        } elseif (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/", $range)) {            list($cell1, $cell2) = split('\.\.', $range);        } else {            // TODO: use real error codes            return $this->raiseError("Unknown range separator", 0, PEAR_ERROR_DIE);        }        // Convert the cell references        $cell_array1 = $this->_cellToPackedRowcol($cell1);        if (PEAR::isError($cell_array1)) {            return $cell_array1;        }        list($row1, $col1) = $cell_array1;        $cell_array2 = $this->_cellToPackedRowcol($cell2);        if (PEAR::isError($cell_array2)) {            return $cell_array2;        }        list($row2, $col2) = $cell_array2;        // The ptg value depends on the class of the ptg.        if ($class == 0) {            $ptgArea = pack("C", $this->ptg['ptgArea']);        } elseif ($class == 1) {            $ptgArea = pack("C", $this->ptg['ptgAreaV']);        } elseif ($class == 2) {            $ptgArea = pack("C", $this->ptg['ptgAreaA']);        } else {            // TODO: use real error codes            return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE);        }        return $ptgArea . $row1 . $row2 . $col1. $col2;    }    /**    * Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to    * a ptgArea3d.    *    * @access private    * @param string $token An Excel range in the Sheet1!A1:A2 format.    * @return mixed The packed ptgArea3d token on success, PEAR_Error on failure.    */    function _convertRange3d($token)    {        $class = 2; // as far as I know, this is magick.        // Split the ref at the ! symbol        list($ext_ref, $range) = split('!', $token);        // Convert the external reference part (different for BIFF8)        if ($this->_BIFF_version == 0x0500) {            $ext_ref = $this->_packExtRef($ext_ref);            if (PEAR::isError($ext_ref)) {                return $ext_ref;            }        } elseif ($this->_BIFF_version == 0x0600) {             $ext_ref = $this->_getRefIndex($ext_ref);             if (PEAR::isError($ext_ref)) {                 return $ext_ref;             }        }        // Split the range into 2 cell refs        list($cell1, $cell2) = split(':', $range);        // Convert the cell references        if (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/", $cell1)) {            $cell_array1 = $this->_cellToPackedRowcol($cell1);            if (PEAR::isError($cell_array1)) {                return $cell_array1;            }            list($row1, $col1) = $cell_array1;            $cell_array2 = $this->_cellToPackedRowcol($cell2);            if (PEAR::isError($cell_array2)) {                return $cell_array2;            }            list($row2, $col2) = $cell_array2;        } else { // It's a rows range (like 26:27)             $cells_array = $this->_rangeToPackedRange($cell1.':'.$cell2);             if (PEAR::isError($cells_array)) {                 return $cells_array;             }             list($row1, $col1, $row2, $col2) = $cells_array;        }        // The ptg value depends on the class of the ptg.        if ($class == 0) {            $ptgArea = pack("C", $this->ptg['ptgArea3d']);        } elseif ($class == 1) {            $ptgArea = pack("C", $this->ptg['ptgArea3dV']);        } elseif ($class == 2) {            $ptgArea = pack("C", $this->ptg['ptgArea3dA']);        } else {            return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE);        }        return $ptgArea . $ext_ref . $row1 . $row2 . $col1. $col2;    }    /**    * Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.    *    * @access private    * @param string $cell An Excel cell reference    * @return string The cell in packed() format with the corresponding ptg    */    function _convertRef2d($cell)    {        $class = 2; // as far as I know, this is magick.        // Convert the cell reference        $cell_array = $this->_cellToPackedRowcol($cell);        if (PEAR::isError($cell_array)) {            return $cell_array;        }        list($row, $col) = $cell_array;        // The ptg value depends on the class of the ptg.        if ($class == 0) {            $ptgRef = pack("C", $this->ptg['ptgRef']);        } elseif ($class == 1) {            $ptgRef = pack("C", $this->ptg['ptgRefV']);        } elseif ($class == 2) {            $ptgRef = pack("C", $this->ptg['ptgRefA']);        } else {            // TODO: use real error codes            return $this->raiseError("Unknown class $class");        }        return $ptgRef.$row.$col;    }    /**    * Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a    * ptgRef3d.    *    * @access private    * @param string $cell An Excel cell reference    * @return mixed The packed ptgRef3d token on success, PEAR_Error on failure.    */    function _convertRef3d($cell)    {        $class = 2; // as far as I know, this is magick.        // Split the ref at the ! symbol        list($ext_ref, $cell) = split('!', $cell);        // Convert the external reference part (different for BIFF8)        if ($this->_BIFF_version == 0x0500) {            $ext_ref = $this->_packExtRef($ext_ref);            if (PEAR::isError($ext_ref)) {                return $ext_ref;            }        } elseif ($this->_BIFF_version == 0x0600) {            $ext_ref = $this->_getRefIndex($ext_ref);            if (PEAR::isError($ext_ref)) {                return $ext_ref;            }        }        // Convert the cell reference part        list($row, $col) = $this->_cellToPackedRowcol($cell);        // The ptg value depends on the class of the ptg.        if ($class == 0) {            $ptgRef = pack("C", $this->ptg['ptgRef3d']);        } elseif ($class == 1) {            $ptgRef = pack("C", $this->ptg['ptgRef3dV']);        } elseif ($class == 2) {            $ptgRef = pack("C", $this->ptg['ptgRef3dA']);        } else {            return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE);        }        return $ptgRef . $ext_ref. $row . $col;    }    /**    * Convert the sheet name part of an external reference, for example "Sheet1" or    * "Sheet1:Sheet2", to a packed structure.    *    * @access private    * @param string $ext_ref The name of the external reference    * @return string The reference index in packed() format    */    function _packExtRef($ext_ref)    {        $ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading  ' if any.        $ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.        // Check if there is a sheet range eg., Sheet1:Sheet2.        if (preg_match("/:/", $ext_ref)) {            list($sheet_name1, $sheet_name2) = split(':', $ext_ref);            $sheet1 = $this->_getSheetIndex($sheet_name1);            if ($sheet1 == -1) {                return $this->raiseError("Unknown sheet name $sheet_name1 in formula");            }            $sheet2 = $this->_getSheetIndex($sheet_name2);            if ($sheet2 == -1) {                return $this->raiseError("Unknown sheet name $sheet_name2 in formula");            }            // Reverse max and min sheet numbers if necessary            if ($sheet1 > $sheet2) {                list($sheet1, $sheet2) = array($sheet2, $sheet1);            }        } else { // Single sheet name only.            $sheet1 = $this->_getSheetIndex($ext_ref);            if ($sheet1 == -1) {                return $this->raiseError("Unknown sheet name $ext_ref in formula");            }            $sheet2 = $sheet1;        }        // References are stored relative to 0xFFFF.        $offset = -1 - $sheet1;        return pack('vdvv', $offset, 0x00, $sheet1, $sheet2);    }    /**    * Look up the REF index that corresponds to an external sheet name    * (or range). If it doesn't exist yet add it to the workbook's references    * array. It assumes all sheet names given must exist.    *    * @access private    * @param string $ext_ref The name of the external reference    * @return mixed The reference index in packed() format on success,    *               PEAR_Error on failure    */    function _getRefIndex($ext_ref)    {        $ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading  ' if any.        $ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.        // Check if there is a sheet range eg., Sheet1:Sheet2.        if (preg_match("/:/", $ext_ref)) {            list($sheet_name1, $sheet_name2) = split(':', $ext_ref);            $sheet1 = $this->_getSheetIndex($sheet_name1);            if ($sheet1 == -1) {                return $this->raiseError("Unknown sheet name $sheet_name1 in formula");            }            $sheet2 = $this->_getSheetIndex($sheet_name2);            if ($sheet2 == -1) {                return $this->raiseError("Unknown sheet name $sheet_name2 in formula");            }            // Reverse max and min sheet numbers if necessary            if ($sheet1 > $sheet2) {                list($sheet1, $sheet2) = array($sheet2, $sheet1);            }        } else { // Single sheet name only.            $sheet1 = $this->_getSheetIndex($ext_ref);            if ($sheet1 == -1) {                return $this->raiseError("Unknown sheet name $ext_ref in formula");            }            $sheet2 = $sheet1;        }        // assume all references belong to this document        $supbook_index = 0x00;        $ref = pack('vvv', $supbook_index, $sheet1, $sheet2);        $total_references = count($this->_references);        $index = -1;        for ($i = 0; $i < $total_references; $i++) {            if ($ref == $this->_references[$i]) {                $index = $i;                break;            }        }        // if REF was not found add it to references array        if ($index == -1) {            $this->_references[$total_references] = $ref;            $index = $total_references;        }        return pack('v', $index);    }    /**    * Look up the index that corresponds to an external sheet name. The hash of    * sheet names is updated by the addworksheet() method of the    * Spreadsheet_Excel_Writer_Workbook class.    *    * @access private    * @return integer The sheet index, -1 if the sheet was not found    */    function _getSheetIndex($sheet_name)    {        if (!isset($this->_ext_sheets[$sheet_name])) {            return -1;        } else {            return $this->_ext_sheets[$sheet_name];        }    }    /**    * This method is used to update the array of sheet names. It is    * called by the addWorksheet() method of the    * Spreadsheet_Excel_Writer_Workbook class.    *    * @access public    * @see Spreadsheet_Excel_Writer_Workbook::addWorksheet()    * @param string  $name  The name of the worksheet being added    * @param integer $index The index of the worksheet being added    */    function setExtSheet($name, $index)    {        $this->_ext_sheets[$name] = $index;    }    /**    * pack() row and column into the required 3 or 4 byte format.    *    * @access private    * @param string $cell The Excel cell reference to be packed    * @return array Array containing the row and column in packed() format    */    function _cellToPackedRowcol($cell)    {        $cell = strtoupper($cell);        list($row, $col, $row_rel, $col_rel) = $this->_cellToRowcol($cell);        if ($col >= 256) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -