How to close excel file in php-excel-reader

大兔子大兔子 提交于 2020-01-25 10:26:07

问题


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

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

here is my code

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);
  }

回答1:


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;
}

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);


来源:https://stackoverflow.com/questions/17161925/how-to-close-excel-file-in-php-excel-reader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!