notices with addsheet() creating new file

Jan 31, 2011 at 10:57 AM

Hi,

I am trying to make a new xlsx file containing all sheets from different xlsx files by using  the function addsheet.  The names of the files are in a array : $namesheet. The files contain only one sheet.

The code works but I lose the format and I have some notices :

Notice: Undefined offset: 3 in C:           \Classes\PHPExcel.php on line 729
...
Notice: Undefined offset: 1 in C:           \Classes\PHPExcel.php on line 774

 

code :


foreach ($namesheet as $contenu)
        {
            $objReader= PHPExcel_IOFactory::createReader('Excel2007');
            $objReader->setReadFilter( new MyReadFilter() );
            $fichier=$repertoire.'/'.$contenu.'.xlsx';
            try
            {
                $objPHPExcel[$k] = $objReader->load($fichier);
            } catch(Exception $e) {
                die('Erreur chargement du fichier : '.$fichier);
            }
            $k++;
        }
        $writer = new PHPExcel();
        for($kk=0;$kk<$k ;$kk++)
        {   
            for($ii=0;$ii<$objPHPExcel[$kk]->getSheetCount();$ii++)
            {
                $writer->addSheet($objPHPExcel[$kk]->getSheet());
            }
        }
        $save = PHPExcel_IOFactory::createWriter($writer,'Excel2007');
        $save->save($repertoire."/".$nom."--".$autre.".xlsx");
    }

 

Thank you for your help

Jan 31, 2011 at 12:37 PM

Hi,

I fixe the problem using addExernalSheet :

$writer->addExernalSheet($objPHPExcel[$kk]->getSheet()),$k-1);

Sorry for your time