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

📄 worksheet.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
        $this->_hcenter = $center;    }    /**    * Center the page vertically.    *    * @access public    * @param integer $center the optional value for centering. Defaults to 1 (center).    */    function centerVertically($center = 1)    {        $this->_vcenter = $center;    }    /**    * Set all the page margins to the same value in inches.    *    * @access public    * @param float $margin The margin to set in inches    */    function setMargins($margin)    {        $this->setMarginLeft($margin);        $this->setMarginRight($margin);        $this->setMarginTop($margin);        $this->setMarginBottom($margin);    }    /**    * Set the left and right margins to the same value in inches.    *    * @access public    * @param float $margin The margin to set in inches    */    function setMargins_LR($margin)    {        $this->setMarginLeft($margin);        $this->setMarginRight($margin);    }    /**    * Set the top and bottom margins to the same value in inches.    *    * @access public    * @param float $margin The margin to set in inches    */    function setMargins_TB($margin)    {        $this->setMarginTop($margin);        $this->setMarginBottom($margin);    }    /**    * Set the left margin in inches.    *    * @access public    * @param float $margin The margin to set in inches    */    function setMarginLeft($margin = 0.75)    {        $this->_margin_left = $margin;    }    /**    * Set the right margin in inches.    *    * @access public    * @param float $margin The margin to set in inches    */    function setMarginRight($margin = 0.75)    {        $this->_margin_right = $margin;    }    /**    * Set the top margin in inches.    *    * @access public    * @param float $margin The margin to set in inches    */    function setMarginTop($margin = 1.00)    {        $this->_margin_top = $margin;    }    /**    * Set the bottom margin in inches.    *    * @access public    * @param float $margin The margin to set in inches    */    function setMarginBottom($margin = 1.00)    {        $this->_margin_bottom = $margin;    }    /**    * Set the rows to repeat at the top of each printed page.    *    * @access public    * @param integer $first_row First row to repeat    * @param integer $last_row  Last row to repeat. Optional.    */    function repeatRows($first_row, $last_row = null)    {        $this->title_rowmin  = $first_row;        if (isset($last_row)) { //Second row is optional            $this->title_rowmax  = $last_row;        } else {            $this->title_rowmax  = $first_row;        }    }    /**    * Set the columns to repeat at the left hand side of each printed page.    *    * @access public    * @param integer $first_col First column to repeat    * @param integer $last_col  Last column to repeat. Optional.    */    function repeatColumns($first_col, $last_col = null)    {        $this->title_colmin  = $first_col;        if (isset($last_col)) { // Second col is optional            $this->title_colmax  = $last_col;        } else {            $this->title_colmax  = $first_col;        }    }    /**    * Set the area of each worksheet that will be printed.    *    * @access public    * @param integer $first_row First row of the area to print    * @param integer $first_col First column of the area to print    * @param integer $last_row  Last row of the area to print    * @param integer $last_col  Last column of the area to print    */    function printArea($first_row, $first_col, $last_row, $last_col)    {        $this->print_rowmin  = $first_row;        $this->print_colmin  = $first_col;        $this->print_rowmax  = $last_row;        $this->print_colmax  = $last_col;    }    /**    * Set the option to hide gridlines on the printed page.    *    * @access public    */    function hideGridlines()    {        $this->_print_gridlines = 0;    }    /**    * Set the option to hide gridlines on the worksheet (as seen on the screen).    *    * @access public    */    function hideScreenGridlines()    {        $this->_screen_gridlines = 0;    }    /**    * Set the option to print the row and column headers on the printed page.    *    * @access public    * @param integer $print Whether to print the headers or not. Defaults to 1 (print).    */    function printRowColHeaders($print = 1)    {        $this->_print_headers = $print;    }    /**    * Set the vertical and horizontal number of pages that will define the maximum area printed.    * It doesn't seem to work with OpenOffice.    *    * @access public    * @param  integer $width  Maximun width of printed area in pages    * @param  integer $height Maximun heigth of printed area in pages    * @see setPrintScale()    */    function fitToPages($width, $height)    {        $this->_fit_page      = 1;        $this->_fit_width     = $width;        $this->_fit_height    = $height;    }    /**    * Store the horizontal page breaks on a worksheet (for printing).    * The breaks represent the row after which the break is inserted.    *    * @access public    * @param array $breaks Array containing the horizontal page breaks    */    function setHPagebreaks($breaks)    {        foreach ($breaks as $break) {            array_push($this->_hbreaks, $break);        }    }    /**    * Store the vertical page breaks on a worksheet (for printing).    * The breaks represent the column after which the break is inserted.    *    * @access public    * @param array $breaks Array containing the vertical page breaks    */    function setVPagebreaks($breaks)    {        foreach ($breaks as $break) {            array_push($this->_vbreaks, $break);        }    }    /**    * Set the worksheet zoom factor.    *    * @access public    * @param integer $scale The zoom factor    */    function setZoom($scale = 100)    {        // Confine the scale to Excel's range        if ($scale < 10 || $scale > 400) {            $this->raiseError("Zoom factor $scale outside range: 10 <= zoom <= 400");            $scale = 100;        }        $this->_zoom = floor($scale);    }    /**    * Set the scale factor for the printed page.    * It turns off the "fit to page" option    *    * @access public    * @param integer $scale The optional scale factor. Defaults to 100    */    function setPrintScale($scale = 100)    {        // Confine the scale to Excel's range        if ($scale < 10 || $scale > 400) {            $this->raiseError("Print scale $scale outside range: 10 <= zoom <= 400");            $scale = 100;        }        // Turn off "fit to page" option        $this->_fit_page = 0;        $this->_print_scale = floor($scale);    }    /**    * Map to the appropriate write method acording to the token recieved.    *    * @access public    * @param integer $row    The row of the cell we are writing to    * @param integer $col    The column of the cell we are writing to    * @param mixed   $token  What we are writing    * @param mixed   $format The optional format to apply to the cell    */    function write($row, $col, $token, $format = null)    {        // Check for a cell reference in A1 notation and substitute row and column        /*if ($_[0] =~ /^\D/) {            @_ = $this->_substituteCellref(@_);    }*/        if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) {            // Match number            return $this->writeNumber($row, $col, $token, $format);        } elseif (preg_match("/^[fh]tt?p:\/\//", $token)) {            // Match http or ftp URL            return $this->writeUrl($row, $col, $token, '', $format);        } elseif (preg_match("/^mailto:/", $token)) {            // Match mailto:            return $this->writeUrl($row, $col, $token, '', $format);        } elseif (preg_match("/^(?:in|ex)ternal:/", $token)) {            // Match internal or external sheet link            return $this->writeUrl($row, $col, $token, '', $format);        } elseif (preg_match("/^=/", $token)) {            // Match formula            return $this->writeFormula($row, $col, $token, $format);        } elseif (preg_match("/^@/", $token)) {            // Match formula            return $this->writeFormula($row, $col, $token, $format);        } elseif ($token == '') {            // Match blank            return $this->writeBlank($row, $col, $format);        } else {            // Default: match string            return $this->writeString($row, $col, $token, $format);        }    }    /**    * Write an array of values as a row    *    * @access public    * @param integer $row    The row we are writing to    * @param integer $col    The first col (leftmost col) we are writing to    * @param array   $val    The array of values to write    * @param mixed   $format The optional format to apply to the cell    * @return mixed PEAR_Error on failure    */    function writeRow($row, $col, $val, $format = null)    {        $retval = '';        if (is_array($val)) {            foreach ($val as $v) {                if (is_array($v)) {                    $this->writeCol($row, $col, $v, $format);                } else {                    $this->write($row, $col, $v, $format);                }                $col++;            }        } else {            $retval = new PEAR_Error('$val needs to be an array');        }        return($retval);    }    /**    * Write an array of values as a column    *    * @access public    * @param integer $row    The first row (uppermost row) we are writing to    * @param integer $col    The col we are writing to    * @param array   $val    The array of values to write    * @param mixed   $format The optional format to apply to the cell    * @return mixed PEAR_Error on failure    */    function writeCol($row, $col, $val, $format = null)    {        $retval = '';        if (is_array($val)) {            foreach ($val as $v) {                $this->write($row, $col, $v, $format);                $row++;            }        } else {            $retval = new PEAR_Error('$val needs to be an array');        }        return($retval);    }    /**    * Returns an index to the XF record in the workbook    *    * @access private    * @param mixed &$format The optional XF format    * @return integer The XF record index    */    function _XF(&$format)    {        if ($format) {            return($format->getXfIndex());        } else {            return(0x0F);        }    }    /******************************************************************************    *******************************************************************************    *    * Internal methods    */    /**    * Store Worksheet data in memory using the parent's class append() or to a    * temporary file, the default.    *    * @access private    * @param string $data The binary data to append    */    function _append($data)    {        if ($this->_using_tmpfile) {            // Add CONTINUE records if necessary            if (strlen($data) > $this->_limit) {                $data = $this->_addContinue($data);            }            fwrite($this->_filehandle, $data);            $this->_datasize += strlen($data);        } else {            parent::_append($data);        }    }    /**    * Substitute an Excel cell reference in A1 notation for  zero based row and    * column values in an argument list.    *    * Ex: ("A4", "Hello") is converted to (3, 0, "Hello").    *    * @access private    * @param string $cell The cell reference. Or range of cells.    * @return array    */    function _substituteCellref($cell)    {        $cell = strtoupper($cell);        // Convert a column range: 'A:A' or 'B:G'        if (preg_match("/([A-I]?[A-Z]):([A-I]?[A-Z])/", $cell, $match)) {            list($no_use, $col1) =  $this->_cellToRowcol($match[1] .'1'); // Add a dummy row            list($no_use, $col2) =  $this->_cellToRowcol($match[2] .'1'); // Add a dummy row            return(array($col1, $col2));        }        // Convert a cell range: 'A1:B7'        if (preg_match("/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/", $cell, $match)) {            list($row1, $col1) =  $this->_cellToRowcol($match[1]);            list($row2, $col2) =  $this->_cellToRowcol($match[2]);            return(array($row1, $col1, $row2, $col2));        }

⌨️ 快捷键说明

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