Eliza985 Posted March 13, 2012 Share Posted March 13, 2012 Hi, I need your help if you can. I generate a Excel file and now I need a ne tab in it called "fluturas2'" that will generate what is in the tab called "fluturasi" but on columns. can you please help!!! <?php if (!isset($_SESSION['ADMIN_LOADED'])) die(); require_once config :: $site['lib_path'].'/Excel/PHPExcel.php'; if (!isset($_GET['act'])) $_GET['act'] = ''; //$db -> show_queries=true; $db->query("SET NAMES utf8"); switch($_GET['act']){ case 'nurserevolution': $db -> query ('SELECT * FROM report_nurse_evaluations WHERE period="'.$_GET['period'].'" AND country = "'.$_GET['country'].'"'); $infos = $db -> fetch_row_set(); $objPHPExcel = new PHPExcel(); $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT); $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); $curent_line = 5; $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('Arial'); $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(12); $table_headers = array( 'Asistenta', 'Perioada', 'Nr tichete', 'Nr carduri primite', 'Nr carduri valide', 'Nr carduri invalide (fara adresa/fara nume mama/fara data nastere copil/fara sexul copilului/fara semnatura)', /* ' -fara adresa', ' -fara nume mama', ' -fara data nastere copil', ' -fara sexul copilului', */ 'Nr carduri incomplete ( fara telefon)', //' -fara semnatura', 'inmanare “pachet”', 'transmitere mesaj catre mamica', 'completare rapoarte lunare', 'atingerea unui minimun de 95% de cupoane completate integral, in raport cu totalul mamelor care au nascut intr-o anumita luna' ); $styleArray = array( 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN ) ) ); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25); $w=0; foreach ($infos as $key => $i){ if (trim($i['text'])!="") $infos[$key]['text'] = @unserialize($i['text']); unset($infos[$key]['text']['html']); $infos[$key]['invalid_cards_wo_addres'] = 0; $infos[$key]['invalid_cards_wo_mname'] = 0; $infos[$key]['invalid_cards_wo_kiddob'] = 0; $infos[$key]['invalid_cards_wo_kidsex'] = 0; $infos[$key]['invalid_cards_wo_tel'] = 0; $infos[$key]['invalid_cards_wo_sem'] = 0; //printr(($infos[$key]['cards_invalid'])); //printr($infos[$key]['text']);die(); if (count($infos[$key]['text']['invlaid_cards'])){ //echo "xxx"; foreach ($infos[$key]['text']['invlaid_cards'] as $invalid_c){ //printr($invalid_c); //die(); if (trim($invalid_c['Adresa?'])==='N') $infos[$key]['invalid_cards_wo_addres']++; if (trim($invalid_c['Numele mamei?'])==='N') $infos[$key]['invalid_cards_wo_mname']++; if (trim($invalid_c['Data nasterii?'])==='N') $infos[$key]['invalid_cards_wo_kiddob']++; if (trim($invalid_c['Sexul copilului?'])==='N') $infos[$key]['invalid_cards_wo_kidsex']++; if (trim($invalid_c['Telefon?'])==='N') $infos[$key]['invalid_cards_wo_tel']++; if (trim($invalid_c['Semnat?'])==='N') $infos[$key]['invalid_cards_wo_sem']++; } } $i['months'] = explode(',',$i['months']); $months =array(); foreach ($i['months'] as $m){ $months[]=date('M Y',strtotime('01-'.$m)); } $infos[$key]['months_str']= implode(', ',$months); $value = array( $infos[$key]['nurse'], $infos[$key]['months_str'], $infos[$key]['tickets'], $infos[$key]['cards_sampled'], $infos[$key]['cards_valid'], $infos[$key]['cards_invalid'], //$infos[$key]['invalid_cards_wo_addres'], //$infos[$key]['invalid_cards_wo_mname'], //$infos[$key]['invalid_cards_wo_kiddob'], //$infos[$key]['invalid_cards_wo_kidsex'], $infos[$key]['invalid_cards_wo_tel'], //$infos[$key]['invalid_cards_wo_sem'], 'Da', 'Da', 'Da', 'Da' ); $first_line = $curent_line; foreach ($table_headers as $k => $th){ $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A'.$curent_line, $th) ->setCellValue('B'.$curent_line, $value[$k]); $curent_line++; } $objPHPExcel->getActiveSheet()->getStyle('A'.$first_line.':B'.($curent_line-1))->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setBreak('C'.$curent_line, PHPExcel_Worksheet::BREAK_ROW); $curent_line=$curent_line+5; } $objPHPExcel->getActiveSheet()->setTitle('fluturas'); $objPHPExcel->createSheet(); //$objPHPExcel->setActiveSheetIndex(2) ; $curent_line = 4; $objPHPExcel->setActiveSheetIndex(2) ->setCellValue('A'.$curent_line , 'Asistenta') ->setCellValue('B'.$curent_line , 'Perioada') ->setCellValue('C'.$curent_line , 'Nr tichete') ->setCellValue('D'.$curent_line , 'Nr carduri primite') ->setCellValue('E'.$curent_line , 'Nr carduri valide') ->setCellValue('F'.$curent_line , 'Nr carduri invalide (fara adresa/fara nume mama/fara data nastere copil/fara sexul copilului/fara semnatura)') ->setCellValue('G'.$curent_line , 'Nr carduri incomplete (fara telefon)') ->setCellValue('H'.$curent_line , 'Inmanare “pachet"') ->setCellValue('I'.$curent_line , 'Transmitere mesaj catre mamica') ->setCellValue('J'.$curent_line , 'Completare rapoarte lunare') ->setCellValue('K'.$curent_line , 'Atingerea unui minimun de 95% de cupoane completate integral, in raport cu totalul mamelor care au nascut intr-o anumita luna'); $curent_line++; foreach ($infos as $i){ $objPHPExcel->setActiveSheetIndex(2) ->setCellValue('A'.$curent_line , $i['nurse']) ->setCellValue('B'.$curent_line , $i['months_str']) ->setCellValue('C'.$curent_line , $i['tickets']) ->setCellValue('D'.$curent_line , $i['cards_sampled']) ->setCellValue('E'.$curent_line , $i['cards_valid']) ->setCellValue('F'.$curent_line , $i['cards_invalid']) ->setCellValue('G'.$curent_line , $i['invalid_cards_wo_tel']) ->setCellValue('H'.$curent_line , 'Da') ->setCellValue('I'.$curent_line , 'Da') ->setCellValue('J'.$curent_line , 'Da') ->setCellValue('K'.$curent_line , 'Da'); $curent_line++; } $objPHPExcel->getActiveSheetIndex3()->setTitle('fluturas2'); //$objPHPExcel->setActiveSheetIndex(1) ; $curent_line = 4; $objPHPExcel->setActiveSheetIndex(1) ->setCellValue('A'.$curent_line , 'Hospital') ->setCellValue('B'.$curent_line , 'Nurse') ->setCellValue('C'.$curent_line , 'Phone') ->setCellValue('D'.$curent_line , 'Code') ->setCellValue('E'.$curent_line , 'Adress') ->setCellValue('F'.$curent_line , 'City') ->setCellValue('G'.$curent_line , 'Region') ->setCellValue('H'.$curent_line , 'Month') ->setCellValue('I'.$curent_line , 'Cards Invalid') ->setCellValue('J'.$curent_line , 'Cards Sampled') ->setCellValue('K'.$curent_line , 'Cards Valid') ->setCellValue('L'.$curent_line , 'Cards Invalid Wo Adress') ->setCellValue('M'.$curent_line , 'Cards Invalid Wo Mother Name') ->setCellValue('N'.$curent_line , 'Cards Invalid Wo Kid date of birth') ->setCellValue('O'.$curent_line , 'Cards Invalid Wo Kid sex') ->setCellValue('P'.$curent_line , 'Cards Invalid Wo Telephone') ->setCellValue('Q'.$curent_line , 'Cards Invalid Wo Signature') ->setCellValue('R'.$curent_line , 'Points') ->setCellValue('S'.$curent_line , 'Amount') ->setCellValue('T'.$curent_line , 'Prev remainder') ->setCellValue('U'.$curent_line , 'Total') ->setCellValue('V'.$curent_line , 'Tickets') ->setCellValue('W'.$curent_line , 'Reminder') ->setCellValue('X'.$curent_line , 'Da') ->setCellValue('Y'.$curent_line , 'Da') ->setCellValue('Z'.$curent_line , 'Da'); $curent_line++; foreach ($infos as $i){ $objPHPExcel->setActiveSheetIndex(1) ->setCellValue('A'.$curent_line , $i['hospital']) ->setCellValue('B'.$curent_line , $i['nurse']) ->setCellValue('C'.$curent_line , html_entity_decode($i['phone'])) ->setCellValue('D'.$curent_line , $i['code']) ->setCellValue('E'.$curent_line , $i['address']) ->setCellValue('F'.$curent_line , $i['city']) ->setCellValue('G'.$curent_line , $i['region']) ->setCellValue('H'.$curent_line , $i['months_str']) ->setCellValue('I'.$curent_line , $i['cards_invalid']) ->setCellValue('J'.$curent_line , $i['cards_sampled']) ->setCellValue('K'.$curent_line , $i['cards_valid']) ->setCellValue('L'.$curent_line , $i['invalid_cards_wo_addres']) ->setCellValue('M'.$curent_line , $i['invalid_cards_wo_mname']) ->setCellValue('N'.$curent_line , $i['invalid_cards_wo_kiddob']) ->setCellValue('O'.$curent_line , $i['invalid_cards_wo_kidsex']) ->setCellValue('P'.$curent_line , $i['invalid_cards_wo_tel']) ->setCellValue('Q'.$curent_line , $i['invalid_cards_wo_sem']) ->setCellValue('R'.$curent_line , $i['points']) ->setCellValue('S'.$curent_line , $i['amount']) ->setCellValue('T'.$curent_line , $i['previous_remainder']) ->setCellValue('U'.$curent_line , $i['total']) ->setCellValue('V'.$curent_line , $i['tickets']) ->setCellValue('W'.$curent_line , $i['remainder']) ->setCellValue('X'.$curent_line , 'Da') ->setCellValue('Y'.$curent_line , 'Da') ->setCellValue('Z'.$curent_line , 'Da'); $curent_line++; } $objPHPExcel->getActiveSheet()->setTitle('template centralizator fluturas'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="Raport Nurse.xls"'); header('Cache-Control: max-age=0'); $objWriter->save('php://output'); die(); break; } print '1234'; die(); ?> MOD EDIT: . . . BBCode tags added, rule violations removed. Quote Link to comment https://forums.phpfreaks.com/topic/258835-help-please/ Share on other sites More sharing options...
Eliza985 Posted March 13, 2012 Author Share Posted March 13, 2012 I generate (must genearate) a Excel file and now I need a new tab in it called "fluturas2'" that will generate what is in the tab called "fluturas" but on columns. Quote Link to comment https://forums.phpfreaks.com/topic/258835-help-please/#findComment-1326871 Share on other sites More sharing options...
Muddy_Funster Posted March 13, 2012 Share Posted March 13, 2012 never used that class lib, sorry Quote Link to comment https://forums.phpfreaks.com/topic/258835-help-please/#findComment-1326874 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.