需要帮助循环遍历Excel工作表中的每一行,并使用地址调用Web服务并生成包含其他信息的新Excel工作表。 Web服务将生成经度和纬度,创建与您正在读取的相同的新工作表,将经度和纬度复制到正确的列中。
<?php
require_once('PHPExcel.php');
$reader = PHPExcel_IOFactory::createReaderForFile($file);
$excel = $reader->load($file);
$maxCol=$sheet->getHighestColumn();
$maxRow=$sheet->getHighestRow();
// loop through rows
for ($row=2; $row<=$maxRow; $row++) {
// get address fields
$street=$sheet->getCell("C$row")->getValue();
$city=$sheet->getCell("C$row")->getValue();
$state=$sheet->getCell("C$row")->getValue();
$zip=$sheet->getCell("C$row")->getValue();
$o = (object)[
"street" => $street,
"city" => $city,
"state" => $state,
"zip" => $zip
];
$json = json_encode($o);
// call webservice
$response = file_get_contents("www.web.com/geolocate/keywords=".urlencode($json));
$data = json_decode($response);
}