php 2010excel,PHPExcel在php5.2.10上的bug

Fatal error: Class ‘PHPExcel_Worksheet’ not found in /htdocs/webapp/includes/libs/PHPExcel.php on line 114

PHPExcel.php第114行内容

$this->_workSheetCollection[] = new PHPExcel_Worksheet($this);

PHPExcel使用了自动载入class

PHPExcel/Autoloader.php 第43行输入调试代码

echo $pObjectFilePath;

var_dump(file_exists($pObjectFilePath));

echo “

“;

if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) {

return false;

}

/htdocs/webapp/includes/libs/PHPExcel/Shared/ZipStreamWrapper.phpbool(true)

/htdocs/webapp/includes/libs/PHPExcel/Worksheet.phpbool(false)

Fatal error: Class ‘PHPExcel_Worksheet’ not found in /htdocs/webapp/includes/libs/PHPExcel.php on line 114

Worksheet.php文件没有存在?

反复检查了php中open_basedir,文件及目录权限,zip扩展,pear都没问题.

并在autoloader前用代码测试文件确实可以检测到.

var_dump(file_exists(‘/htdocs/webapp/includes/libs/PHPExcel/Worksheet.php’));

试了下把ZipStreamWrapper.php禁止载入后就可顺利通过.

注释PHPExcel.php第34行内容

PHPExcel_Autoloader::Register();

//PHPExcel_Shared_ZipStreamWrapper::register();

看来问题确实在这里,再用代码确认下是stream_register_wrapper和file_exists的bug

class VariableStream {

var $position;

var $varname;

function stream_open($path, $mode, $options, &$opened_path)

{

$url = parse_url($path);

$this->varname = $url[“host”];

$this->position = 0;

return true;

}

function stream_read($count)

{

$ret = substr($GLOBALS[$this->varname], $this->position, $count);

$this->position += strlen($ret);

return $ret;

}

function stream_write($data)

{

$left = substr($GLOBALS[$this->varname], 0, $this->position);

$right = substr($GLOBALS[$this->varname], $this->position + strlen($data));

$GLOBALS[$this->varname] = $left . $data . $right;

$this->position += strlen($data);

return strlen($data);

}

function stream_tell()

{

return $this->position;

}

function stream_eof()

{

return $this->position >= strlen($GLOBALS[$this->varname]);

}

function stream_seek($offset, $whence)

{

switch($whence) {

case SEEK_SET:

if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {

$this->position = $offset;

return true;

} else {

return false;

}

break;

case SEEK_CUR:

if ($offset >= 0) {

$this->position += $offset;

return true;

} else {

return false;

}

break;

case SEEK_END:

if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {

$this->position = strlen($GLOBALS[$this->varname]) + $offset;

return true;

} else {

return false;

}

break;

default:

return false;

}

}

}

var_dump(file_exists(‘/htdocs/webapp/includes/libs/PHPExcel.php’));

stream_register_wrapper(“var”, “VariableStream”)

or die(“Failed to register protocol”);

var_dump(file_exists(‘/htdocs/webapp/includes/libs/PHPExcel.php’));

输出结果

bool(true) bool(false)

解决方法:

1.注释PHPExcel.php第34行内容

PHPExcel_Shared_ZipStreamWrapper::register();

2.更换php版本

目前换成php.5.2.14没有问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好用的phpExcel<?php /** * PHPExcel * * Copyright (c) 2006 - 2009 PHPExcel * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel * @package PHPExcel * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 1.6.6, 2009-03-02 */ /** PHPExcel_Cell */ require_once 'PHPExcel/Cell.php'; /** PHPExcel_DocumentProperties */ require_once 'PHPExcel/DocumentProperties.php'; /** PHPExcel_DocumentSecurity */ require_once 'PHPExcel/DocumentSecurity.php'; /** PHPExcel_Worksheet */ require_once 'PHPExcel/Worksheet.php'; /** PHPExcel_Shared_ZipStreamWrapper */ require_once 'PHPExcel/Shared/ZipStreamWrapper.php'; /** PHPExcel_NamedRange */ require_once 'PHPExcel/NamedRange.php'; /** PHPExcel_WorksheetIterator */ require_once 'PHPExcel/WorksheetIterator.php'; /** * PHPExcel * * @category PHPExcel * @package PHPExcel * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel { /** * Document properties * * @var PHPExcel_DocumentProperties */ private $_properties; /** * Document security * * @var PHPExcel_DocumentSecurity */ private $_security; /** * Collection of Worksheet objects * * @var PHPExcel_Worksheet[] */ private $_workSheetCollection = array(); /** * Active sheet index * * @var int */ private $_activeSheetIndex = 0; /** * Named ranges * * @var PHPExcel_NamedRange[] */ private $_namedRanges = array(); /** * Create a new PHPExcel with one Worksheet */ public function __construct() { // Initialise worksheet collection and add one worksheet $this->_workSheetCollection = array(); $this->_workSheetCollection[] = new PHPExcel_Worksheet($this); $this->_activeSheetIndex = 0; // Create document properties $this->_properties = new PHPExcel_DocumentProperties(); // Create document security $this->_security = new PHPExcel_DocumentSecurity(); // Set named ranges $this->_namedRanges = array(); } /** * Get properties * * @return PHPExcel_DocumentProperties */ public function getProperties() { return $this->_properties; } /** * Set properties * * @param PHPExcel_DocumentProperties $pValue */ public function setProperties(PHPExcel_DocumentProperties $pValue) { $this->_properties = $pValue; } /** * Get security * * @return PHPExcel_DocumentSecurity */ public function getSecurity() { return $this->_security; } /** * Set security * * @param PHPExcel_DocumentSecurity $pValue */ public function setSecurity(PHPExcel_DocumentSecurity $pValue) { $this->_security = $pValue; } /** * Get active sheet * * @return PHPExcel_Worksheet */ public function getActiveSheet() { return $this->_workSheetCollection[$this->_activeSheetIndex]; } /** * Create sheet and add it to this workbook * * @return PHPExcel_Worksheet */ public function createSheet() { $newSheet = new PHPExcel_Worksheet($this); $this->addSheet($newSheet); return $newSheet; } /** * Add sheet * * @param PHPExcel_Worksheet $pSheet * @throws Exception */ public function addSheet(PHPExcel_Worksheet $pSheet = null) { $this->_workSheetCollection[] = $pSheet; } /** * Remove sheet by index * * @param int $pIndex Active sheet index * @throws Exception */ public function removeSheetByIndex($pIndex = 0) { if ($pIndex > count($this->_workSheetCollection) - 1) { throw new Exception("Sheet index is out of bounds."); } else { array_splice($this->_workSheetCollection, $pIndex, 1); } } /** * Get sheet by index * * @param int $pIndex Sheet index * @return PHPExcel_Worksheet * @throws Exception */ public function getSheet($pIndex = 0) { if ($pIndex > count($this->_workSheetCollection) - 1) { throw new Exception("Sheet index is out of bounds."); } else { return $this->_workSheetCollection[$pIndex]; } } /** * Get all sheets * * @return PHPExcel_Worksheet[] */ public function getAllSheets() { return $this->_workSheetCollection; } /** * Get sheet by name * * @param string $pName Sheet name * @return PHPExcel_Worksheet * @throws Exception */ public function getSheetByName($pName = '') { $worksheetCount = count($this->_workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { if ($this->_workSheetCollection[$i]->getTitle() == $pName) { return $this->_workSheetCollection[$i]; } } return null; } /** * Get index for sheet * * @param PHPExcel_Worksheet $pSheet * @return Sheet index * @throws Exception */ public function getIndex(PHPExcel_Worksheet $pSheet) { foreach ($this->_workSheetCollection as $key => $value) { if ($value->getHashCode() == $pSheet->getHashCode()) { return $key; } } } /** * Get sheet count * * @return int */ public function getSheetCount() { return count($this->_workSheetCollection); } /** * Get active sheet index * * @return int Active sheet index */ public function getActiveSheetIndex() { return $this->_activeSheetIndex; } /** * Set active sheet index * * @param int $pIndex Active sheet index * @throws Exception */ public function setActiveSheetIndex($pIndex = 0) { if ($pIndex > count($this->_workSheetCollection) - 1) { throw new Exception("Active sheet index is out of bounds."); } else { $this->_activeSheetIndex = $pIndex; } } /** * Get sheet names * * @return string[] */ public function getSheetNames() { $returnValue = array(); $worksheetCount = $this->getSheetCount(); for ($i = 0; $i < $worksheetCount; ++$i) { array_push($returnValue, $this->getSheet($i)->getTitle()); } return $returnValue; } /** * Add external sheet * * @param PHPExcel_Worksheet $pSheet External sheet to add * @throws Exception */ public function addExternalSheet(PHPExcel_Worksheet $pSheet) { if (!is_null($this->getSheetByName($pSheet->getTitle()))) { throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first."); } $pSheet->rebindParent($this); $this->addSheet($pSheet); } /** * Get named ranges * * @return PHPExcel_NamedRange[] */ public function getNamedRanges() { return $this->_namedRanges; } /** * Add named range * * @param PHPExcel_NamedRange $namedRange */ public function addNamedRange(PHPExcel_NamedRange $namedRange) { $this->_namedRanges[$namedRange->getName()] = $namedRange; } /** * Get named range * * @param string $namedRange */ public function getNamedRange($namedRange) { if ($namedRange != '' && !is_null($namedRange) && @isset($this->_namedRanges[$namedRange])) { return $this->_namedRanges[$namedRange]; } return null; } /** * Remove named range * * @param string $namedRange */ public function removeNamedRange($namedRange) { if ($namedRange != '' && !is_null($namedRange) && @isset($this->_namedRanges[$namedRange])) { unset($this->_namedRanges[$namedRange]); } } /** * Get worksheet iterator * * @return PHPExcel_WorksheetIterator */ public function getWorksheetIterator() { return new PHPExcel_WorksheetIterator($this); } /** * Copy workbook (!= clone!) * * @return PHPExcel */ public function copy() { $copied = clone $this; $worksheetCount = count($this->_workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { $this->_workSheetCollection[$i] = $this->_workSheetCollection[$i]->copy(); $this->_workSheetCollection[$i]->rebindParent($this); } return $copied; } /** * Implement PHP __clone to create a deep clone, not just a shallow copy. */ public function __clone() { $vars = get_object_vars($this); foreach ($vars as $key => $value) { if (is_object($value)) { $this->$key = clone $value; } else { $this->$key = $value; } } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值