-1

I have the following array. I want to write this array in excel sheets using PHP.

 try{
    $client = new SoapClient(WSDL_URL, array('cache_wsdl' => WSDL_CACHE, 'trace' => true, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'proxy_host' => SOAP_PROXY_HOST, 'proxy_port' => SOAP_PROXY_PORT));
    $client->__setLocation(WSDL_ENDPOINT_URL);
    $result = $client->MaximiseLostProspectDecision();
    //print_r($result);
    //exit;
    if (!empty($result->lostProspect->lostProspectRow)) 
    {
      foreach ($result->lostProspect->lostProspectRow as $prospect)
      { 
          $fields   =   array();
          foreach($prospect as $key=>$prospect_details)
          {
             $fields[]=$prospect_details;

          }                     
        }       
    }
}

1 Answers1

0
<?php 

ini_set('max_execution_time',0);
error_reporting('ALL');
ini_set('display_errors','On');
ini_set('memory_limit', '51200M');
$email      = $argv[2];
$instance   = $argv[1];


require_once ('Classes/PHPExcel.php');
require_once ('Classes/PHPExcel/IOFactory.php');

$_REQUEST['instance']   = $instance;

require_once dirname(__FILE__).'/../../boot/bootstrap.php';

$date_from      =   date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")-7, date("Y")));
$date_to            =   date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")-1, date("Y")));
$date=date('F Y');
$objPHPExcel = new PHPExcel();

$allProspectArray=array();

try{
    $client = new SoapClient(WSDL_URL, array('cache_wsdl' => WSDL_CACHE, 'trace' => true, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'proxy_host' => SOAP_PROXY_HOST, 'proxy_port' => SOAP_PROXY_PORT));
     $client->__setLocation(WSDL_ENDPOINT_URL);


         //*********** KEEP ALL Funation /.P file In a Array for Dynmaiclly call **************//

        $allProspectArray['Decision'] ='MaximiseLostProspectDecision';
        $allProspectArray['Duplicate']= 'MaximiseLostProspectDuplicate';
        $allProspectArray['ExitingCustomer']= 'MaximiseLostProspectExisting_Customer';
        $allProspectArray['MoveOrClose']= 'MaximiseLostProspectMove_Or_Close';
        $allProspectArray['NoNeed']= 'MaximiseLostProspectNo_Need';
        $allProspectArray['OptOut']= 'MaximiseLostProspectOpt_Out';
        $allProspectArray['OwnerChange']= 'MaximiseLostProspectOwner_Change';
        $allProspectArray['PoorData']= 'MaximiseLostProspectPoor_Data';
        $allProspectArray['Price']= 'MaximiseLostProspectPrice';
        $allProspectArray['ServiceQuality']= 'MaximiseLostProspectService_Quality';



         $tabCount=count($allProspectArray);
         $tabIndex=0;


             foreach ($allProspectArray as $key=> $resultVal)
             {

                    $result=array() ; //*********** Initialise the array ************//
                    $result=$client->$resultVal(); //********* Progress Function/.p file call //
                    if (!empty($result->lostProspect->lostProspectRow)) 
                    {

                         $fields=array(); 
                         $dataContent=$result->lostProspect->lostProspectRow;
                          foreach ($dataContent as $prospect)
                          { 
                            $fields[]=(array) $prospect;
                          }
                            $filename='';
                            $filename='tmp/activity_csv/'.$key.'.xls';
                            chmod($filename,0777);
                            $tabIndex++;
                            $objPHPExcel->setActiveSheetIndex(0);   
                            $objPHPExcel->getActiveSheet()->setTitle($key);
                            $objPHPExcel->getActiveSheet()->fromArray($fields, null, 'A1');
                            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                            $objWriter->save(str_replace('MaximiseLostProspectBackUp.php',$filename, __FILE__));

                    } 

             }   //************ All Types Prospects End//

    }


   catch (Exception $e) {
            echo "Failed to get data. Error: ".$e->getMessage();
            print_r($e);
            exit;
            }
            ?>