php - Facing issue when trying to generate excel with multiple list drop-downs in same sheet -
i facing issue when trying generate excel more 1 type_list dropdown using phpexcel on symfony 2.8.
i using phpexcel_cell_datavalidation::type_list generate columns of drop-down type. code works fine when generating 1 column in active sheet drop-down. however, when trying generate more 1 columns drop-down type in sheet, getting unusable excel.
here sample screenshot of error getting on opening generated excel,
here action code wrote,
//generating excel using phpexcel public function generateexcel2action(request $request) { $responsestring = 'initial mem. '.(memory_get_peak_usage(true)/1024/1024).' mb <br>'; $starttime = microtime(true); //make new object $objphpexcel = new phpexcel(); //set properties $objphpexcel->getproperties()->setcreator("ramit mitra") ->setlastmodifiedby("ramit mitra") ->settitle("sample excel doc") ->setsubject("office 2007 xlsx test document") ->setdescription("test document office 2007 xlsx, generated using phpexcel.") ->setkeywords("office 2007 openxml php") ->setcategory("test result file"); //excel headers $objphpexcel->setactivesheetindex(0); $objphpexcel->getactivesheet()->setcellvalue('a1', 'shipment number'); $objphpexcel->getactivesheet()->setcellvalue('b1', 'country'); $objphpexcel->getactivesheet()->setcellvalue('c1', 'region'); $objphpexcel->getactivesheet()->setcellvalue('d1', 'choose storage condition'); $objphpexcel->getactivesheet()->setcellvalue('e1', 'choose storage area'); $objphpexcel->getactivesheet()->setcellvalue('f1', 'choose text'); $objphpexcel->getactivesheet()->setcellvalue('g1', 'memory in use'); //query , set data $em = $this->getdoctrine()->getmanager(); //create options $susc = ['cold', 'hot', 'normal']; $susa = ['sm', 'lg', 'xs', 'xl']; $suht = ['text 1', 'text 2', 'text 3']; $i = 2; $allcountries = $em->getrepository('demobundle:country')->findall(); foreach($allcountries $key => $val) { //shpno $objphpexcel->getactivesheet()->setcellvalue("a$i", 'shp'.rand(10000,90000)); //country $objphpexcel->getactivesheet()->setcellvalue("b$i", $val->getname()); //region $objphpexcel->getactivesheet()->setcellvalue("c$i", $val->getregion()->getname()); //choose storage condition $objvalidation = $objphpexcel->getactivesheet()->getcell("d$i")->getdatavalidation(); $objvalidation->settype(\phpexcel_cell_datavalidation::type_list); $objvalidation->seterrorstyle(\phpexcel_cell_datavalidation::style_information); $objvalidation->setallowblank(false); $objvalidation->setshowinputmessage(true); $objvalidation->setshowdropdown(true); $objvalidation->setprompttitle('pick storage condition'); $objvalidation->setprompt('please pick value drop-down list.'); $objvalidation->seterrortitle('input error'); $objvalidation->seterror('value not in list'); $objvalidation->setformula1('"'.implode(',', $susc).'"'); unset($objvalidation); //choose storage area $objvalidation1 = $objphpexcel->getactivesheet()->getcell("e$i")->getdatavalidation(); $objvalidation1->settype(\phpexcel_cell_datavalidation::type_list); $objvalidation1->seterrorstyle(\phpexcel_cell_datavalidation::style_information); $objvalidation1->setallowblank(false); $objvalidation1->setshowinputmessage(true); $objvalidation1->setshowdropdown(true); $objvalidation1->setprompttitle('pick storage area'); $objvalidation1->setprompt('please pick value drop-down list.'); $objvalidation1->seterrortitle('input error'); $objvalidation1->seterror('value not in list'); $objvalidation1->setformula1('"'.implode(',', $susa).'"'); unset($objvalidation1); //choose text $objvalidation2 = $objphpexcel->getactivesheet()->getcell("f$i")->getdatavalidation(); $objvalidation2->settype(\phpexcel_cell_datavalidation::type_list); $objvalidation2->seterrorstyle(\phpexcel_cell_datavalidation::style_information); $objvalidation2->setallowblank(false); $objvalidation2->setshowinputmessage(true); $objvalidation2->setshowdropdown(true); $objvalidation2->setprompttitle('pick text'); $objvalidation2->setprompt('please pick value drop-down list.'); $objvalidation2->seterrortitle('input error'); $objvalidation2->seterror('value not in list'); $objvalidation2->setformula1('"'.implode(',', $suht).'"'); unset($objvalidation2); //mem in use $objphpexcel->getactivesheet()->setcellvalue("g$i", (memory_get_peak_usage(true)/1024/1024).' mb'); $i++; } unset($allcountries); // create writer $objwriter = \phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); $file = $this->get('kernel')->getrootdir() . "\..\web" . $this->getrequest()->getbasepath()."/temp/test2.xlsx"; $objwriter->save($file); unset($objwriter); $endtime = microtime(true) - $starttime; $responsestring .= 'final mem. '.(memory_get_peak_usage(true)/1024/1024).' mb <br>'."file generated @ $file <br>executed in :: $endtime"; unset($starttime); unset($endtime); //send response return new response($responsestring); }
please provide solution this. need generate multiple columns in same sheet drop-downs.
basic env details: windows 7 os, php 7.1.1 on xampp symfony 2.8.26
Comments
Post a Comment