如何在php-excel-reader中关闭Excel文件 [英] How to close excel file in php-excel-reader

查看:618
本文介绍了如何在php-excel-reader中关闭Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php-excel-reader(从此开始)

I am reading two excel file, using php-excel-reader (From this)

读取第一行的两个文件后,我正在对其进行比较.如果它们是相同的,那么我会将文件中的包含附加到其他文件中.要写入文件,我正在使用

After reading two files of 1st row, I am comparing it. If they are same then I am appending contain of on file to other. To write the file I am using this

现在,我想关闭一个文件,但是该功能在php-excel-reader中不可用

Now for doing this I want to close one file, but that function is not available in php-excel-reader

这是我的代码

compare file

{

$data = new Spreadsheet_Excel_Reader($filepath);

$data1 = new Spreadsheet_Excel_Reader($destinationfilepath);

}

unset($data);

unset($data1);


if($flag==0)
{

$excel = new ExcelWriter($destinationfilepath); 

// read the source file

 $finalarray= array();

for($m=1;$m<$sourcefilerowcount;$m++)

    { 

           $charvalue='A';

             $temprow=$m+1;

              for($n=0;$n<$destinationcolnum;$n++)
        {

            $data = new Spreadsheet_Excel_Reader($filepath);

                            $finalarray[$n]=$data->val($temprow,$charvalue);

                            $charvalue++;

                    }

             print_r($finalarray)."<br/>";

     $excel->writeLine($finalarray);
  }

推荐答案

不需要显式调用close()函数,因为该文件会在load()方法中自动关闭.如果查看定义了PHPExcel_Reader_Excel2007的Excel2007.php,您将看到:

There is no need to explicitly call close() function, because the file is automatically closed in the load() method. If you look at Excel2007.php, where PHPExcel_Reader_Excel2007 is defined, you'll see:

public function load($pFilename)
{
    ...
    $zip = new ZipArchive;

    $zip->open($pFilename);
    ...
    $zip->close();
    return $excel;
}

只需取消设置PHPExcel_Reader对象,数据就会从内存中删除:

Just unset your PHPExcel_Reader object, and the data will be removed from memory:

$objReader = PHPExcel_IOFactory::createReader('Excel2003XML');
$objPHPExcel = $objReader->load("Excel2003XMLTest.xml");
...
unset($objPHPExcel);
unset($objReader);

这篇关于如何在php-excel-reader中关闭Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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