简体   繁体   中英

How to close excel file in 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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM