类 PHPExcel_RichText 的对象无法转换为 int


Object of class PHPExcel_RichText could not be converted to int

我正在使用 PHPExcel 并尝试通过上传 excel 来生成纬度和经度,但得到以下错误异常:

"类 PHPExcel_RichText 的对象无法转换为 int"

function locationGenerator()

{ $input = 输入::get();

if(isset($input['rules'])) $rules = $input['rules'];
else $rules = array();
if(isset($input['filter1'])) $rules = $input['filter1'];
else $filter1 = false;
if(isset($input['filter2'])) $rules = $input['filter2'];
else $filter2 = false;
if(!($filter = $input['filter'])) $filter = false;
$filter_type = $input['filter_type'];
$file = $_FILES["file"]["tmp_name"];
$inputFileType = 'Excel5';
$inputFileName = $file;
$data = array();
//$file = 'my_tools/input1.xlsx';
ini_set('max_execution_time', 3000);
$inputFileType = PHPExcel_IOFactory::identify($file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$worksheet = $objReader->load($file);
$highest_row = $worksheet->setActiveSheetIndex(0)->getHighestRow();
$highest_col = $worksheet->setActiveSheetIndex(0)->getHighestColumn();
  //return print_r($highest_row);
$worksheet->setActiveSheetIndex(0)->setCellValue('O1','Lat')
          ->setCellValue('P1','Long')
          ->setCellValue('Q1','Loc');
for ($row = 2; $row <=$highest_row ; ++$row) 
{
  $continue = false;
  $chk = $worksheet->setActiveSheetIndex(0)->getCell("O{$row}")->getValue();
  if(!empty($chk) && $chk !='N/A') $continue = true;
  else $continue = false;
  $chk = $worksheet->setActiveSheetIndex(0)->getCell("P{$row}")->getValue();
  if(!empty($chk) && $chk !='N/A') $continue = true;
  else $continue = false;
  $chk = $worksheet->setActiveSheetIndex(0)->getCell("Q{$row}")->getValue();
  if(!empty($chk) && $chk !='N/A') $continue = true;
  else $continue = false;
  if($continue) continue;
  $area = $worksheet->setActiveSheetIndex(0)->getCellByColumnAndRow(1, $row)->getValue();
  $landmark = $worksheet->setActiveSheetIndex(0)->getCellByColumnAndRow(4, $row)->getValue(); 
  $city = $worksheet->setActiveSheetIndex(0)->getCellByColumnAndRow(0, $row)->getValue();
  $media_type = $worksheet->setActiveSheetIndex(0)->getCellByColumnAndRow(2, $row)->getValue();
  if($filter)
  {
    if($filter_type == 'city')
    {
      if(trim($city) != trim($filter)) continue;
    }
    if($filter_type == 'media_type')
    {
      if(trim($media_type) != trim($filter)) continue;
    }
  }
  foreach ($rules as $key => $rule) 
  {
    switch($rule)
    {
      case 'replace':
        $landmark = str_replace($filter1[$key],$filter2[$key],$landmark);
        break;
      case 'remove_after':
        $landmark = explode($filter1[$key])[0];
        break;
      case 'remove_before':
        $landmark = strstr($landmark,$filter1[$key]);
        break;
      case 'remove':
        $landmark = str_replace($filter1[$key],'',$landmark);
        break;      
    }
  }
  if (!strstr($landmark, $area)) $landmark .= ', ' . $area;
  $landmark = $landmark . ', '. $city;
  $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($landmark) . '&sensor=false';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $result = json_decode(curl_exec($ch), true);
  if(isset($result['status'])){
    if($result['status'] == 'OVER_QUERY_LIMIT') continue;
  }
  if(isset($result['results'][0]['geometry']['location']['lat']))
    $x = $result['results'][0]['geometry']['location']['lat'];
  else
    $x = 'N/A';
  if(isset($result['results'][0]['geometry']['location']['lng']))
    $y = $result['results'][0]['geometry']['location']['lng'];
  else
    $y = 'N/A';
  if(isset($result['results'][0]['geometry']['location_type']))
    $l = $result['results'][0]['geometry']['location_type'];
  else
    $l = 'N/A';
  $worksheet->setActiveSheetIndex(0)->setCellValue("O{$row}", $x);
  $worksheet->setActiveSheetIndex(0)->setCellValue("P{$row}", $y);
  $worksheet->setActiveSheetIndex(0)->setCellValue("Q{$row}", $l);
}
foreach(['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q', 'R', 'S', 'T'] as $columnID) {
  $worksheet->setActiveSheetIndex(0)->getColumnDimension($columnID)->setAutoSize(true);
}
$worksheet->setActiveSheetIndex(0)->freezePane('A2');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.'Location"');
$objWriter = PHPExcel_IOFactory::createWriter($worksheet, 'Excel5');
$objWriter->save('php://output');
exit;

}

PHPExcel RichText对象是一个单元格,其中部分文本的格式与文本的其他部分不同。

若要仅从该单元格中检索无格式的文本内容,请使用 RichText 对象的 getPlainText() 方法。然后,您应该能够将其转换为整数。