PHPExcel如何从列A行值获取

时间:2017-11-20 19:55:38

标签: php excel phpexcel

我是PHPExcel的新手,我需要帮助。 如何从列A中的Excel文件获取所有行值并将其放入数组或变量中。

excel example

这是一个案例: 我在列'A'的IP地址列表中,我需要把它放在变量或数组中,它将在API上发送以获取IP的数据,如城市,zip,状态..当用户上传带有IP的excel文件时,它必须发送给API并从API获取响应并将其插入列中。

有人可以在这里帮助我如何从数组或变量中的列'A'获取值吗? 这是我的代码:

<?php    
if(isset($_POST['Submit'])){ //check if form was submitted

$target_dir = 'uploads/';
$target_file = $target_dir . basename($_FILES["filepath"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

move_uploaded_file($_FILES["filepath"]["tmp_name"], $target_file);

}
//get details from api
$ip = ''; 
function ip_details($ip)
    {
    $json = file_get_contents("http://ipinfo.io/{$ip}");
    $details = json_decode($json);
    return $details;
    }

$details = ip_details($ip);


//include PHPExcel libary
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';

$inputFileType = PHPExcel_IOFactory::identify($target_file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($target_file);

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

// Add column headers
$objPHPExcel->getActiveSheet()
            ->setCellValue('A1', 'IP Adresses')
            ->setCellValue('B1', 'City')
            ->setCellValue('C1', "State")
            ->setCellValue('D1', "Zip")
            ;

                // here I need read each row of Column 'A' and here I am stuck
                $sheet = $objPHPExcel->getSheet(0);
                $highestRow = $sheet->getHighestRow();
                $highestColumn = $sheet->getHighestColumn();




$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($target_file);

?>

0 个答案:

没有答案