phpExcel:无法加载资源:net :: ERR_CONNECTION_RESET [英] phpExcel : Failed to load resource: net::ERR_CONNECTION_RESET

查看:214
本文介绍了phpExcel:无法加载资源:net :: ERR_CONNECTION_RESET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上使用phpExcel来获取一个Excel文件,我用<input type='file'>从用户中恢复了该文件,并在将这个Excel文件转换为csv文件之后.

I actualy use phpExcel to get an excel file that i recover from the user with an <input type='file'> and after i convert this excel file in csv file.

我的脚本工作并且生成了csv文件.问题是我的脚本完成后,页面永不停止加载,并且在控制台中出现此错误:Failed to load resource: net::ERR_CONNECTION_RESET.

My script work and the csv file is generate. The problem is after my script finish the page never stop to loading and i get this error in my console : Failed to load resource: net::ERR_CONNECTION_RESET.

这是另一个问题,我在脚本中还使用了另一个对象来显示菜单,而菜单不显示是我使用了PHPExcel.

Their is another problem i use also an other object in my script for display the menu and the menu don't display is i use PHPExcel.

这是我用来调用PHPExcel对象创建的代码:

Their is my code for call my PHPExcel object creation :

<?php
///Get excelFile ///        
if(isset($_FILES['excelFileCandidat']))
{
   require_once dirname(__FILE__) . "/../../lib/ExcelCandidat/ExcelCandidat.class.php";
   $file = new ExcelCandidat($_FILES['excelFileCandidat']);
   $file->excelFileToCsv();
}



echo "<table width='100%'>";
echo     "<tr>";
echo        "<td>";
echo           "Import new Excel File : ";
echo           "<input type='file' name='excelFileCandidat' />";
echo        "</td>";
echo        "<td>";
echo           "<input type='submit' name='submit' value='Send' />";
echo        "</td>";
echo     "</tr>";
echo "</table>";
?>

还有我的对象:

<?php
require_once dirname(__FILE__) . "/../PHPExcel/PHPExcel.php";

class ExcelCandidat
{
    private $excelFile;
    public function __construct($file)
    {
        $this->excelFile = $file;
    }

    public function excelFileToCsv()
    {
        set_time_limit(600);
        if (!is_array($this->excelFile))
        {
             throw new Exception("STR_APPROCHECK_ERR");
        }

        $newFilename = 'csvCandidat';
        $ext = strrchr($this->excelFile['name'], '.');
        $isExcel = stripos($ext, '.xls') !== false;
        if($isExcel) 
        {
            ini_set('memory_limit', '256M');
            $objPHPExcel = PHPExcel_IOFactory::load($this->excelFile['tmp_name']);
            $worksheet = $objPHPExcel->getActiveSheet();
            $writer = PHPExcel_IOFactory::createWriter($objPHPExcel , 'CSV');
            $writer->setDelimiter(';');
            $writer->setEnclosure('"');
            $writer->setUseBOM(false);
            $tmpName = dirname(__FILE__) . '/file/' . $newFilename . date('ymdHis') .'.csv';
            $writer->save($tmpName);
            unset($objPHPExcel, $writer);
        }
    }
}
?>

推荐答案

我发现问题来自文件PHPExcel/Calculation.php中的库.

I find the problem come from the library in the file PHPExcel/Calculation.php.

您必须在类PHPExcel_Calculation的开头添加一行,然后添加private $saveThis;行,并在构造函数(1722行)中添加line $this->saveThis = $this;,在destruct函数(1740行)中,将remplace $this替换为$saveThis

You have to add a line at the begin of the class PHPExcel_Calculation add a line private $saveThis; and in the construct function(line 1722) add a line $this->saveThis = $this; and in the destruct function (line 1740) remplace $this by $saveThis

这篇关于phpExcel:无法加载资源:net :: ERR_CONNECTION_RESET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆