我有多个数组,我想使用PHP将每个数组写入Excel工作表的每个选项卡
我有以下数组。我想用PHP在excel表格中编写这个数组我有多个数组,我想使用PHP将每个数组写入Excel工作表的每个选项卡,php,Php,我有以下数组。我想用PHP在excel表格中编写这个数组 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));
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;
}
}
}
}
如果您不知道如何在PHP中编写CSV文件,也许最好学习:我知道如何编写CSV,但我想在excel工作表的多个选项卡中编写多个数组。在这种情况下,你应该编辑你的问题以更好地解释你想要的:)尝试此库:我正在使用此库,但没有得到所需的结果。你能帮助我吗?
<?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;
}
?>