php - PHPExcel proble with importing 2 .csv to separate sheets -
mission: need add 2 .csv files separate sheets problem: second import removes second created sheet , puts information on first sheet
$inputfiletype = 'csv'; $objreader = phpexcel_iofactory::createreader($inputfiletype); $objreader->setdelimiter(';'); $objphpexcel = $objreader->load('fail1.csv'); $objphpexcel->getactivesheet()->settitle('laoseis'); //teine leht $objphpexcel->createsheet(); $objphpexcel->setactivesheetindex(1); $objreader = phpexcel_iofactory::createreader($inputfiletype); $objreader->setdelimiter(';'); $objphpexcel->setactivesheetindex(1); $objphpexcel = $objreader->load('fail2.csv'); $date = new datetime($_get['startdate']); $objphpexcel->getactivesheet()->settitle('müük w'.$date->format("w").'');
how can solve problem?
phpexcel doesn't load second file current sheet in existing phpexcel object, creates new phpexcel object , loads file that, you're replacing first when try load second.
load each csv separate phpexcel instance, copy worksheet second instance first.
$objreader1 = phpexcel_iofactory::createreader($inputfiletype); $objphpexcel1 = $objreader1->load('fail1.csv'); $objreader2 = phpexcel_iofactory::createreader($inputfiletype); $objphpexcel2 = $objreader2->load('fail2.csv'); $objphpexcel2->getactivesheet()->settitle('worksheet 2'); $objphpexcel1->addexternalsheet($objphpexcel2->getactivesheet());
now $objphpexcel1
has both worksheets, , can save that
Comments
Post a Comment