-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;

          }                     
        }       
    }
}
5
  • If you don't know how to write CSV files in PHP, maybe it's best to learn: stackoverflow.com/questions/15501463/creating-csv-file-with-php Commented Aug 19, 2015 at 12:32
  • I know how to write CSV but i want to write multiple array in multiple tab of excel sheet. Commented Aug 19, 2015 at 12:38
  • In that case, you should edit your question to better explain what you want :) Commented Aug 19, 2015 at 12:44
  • Try this library: phpexcel.codeplex.com Commented Aug 19, 2015 at 13:01
  • I am using this library but m not getting the required result.Could you please help? Commented Aug 19, 2015 at 13:07

1 Answer 1

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;
            }
            ?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.