[英]PHPExcel - How to calculate a value based on the data from an excel sheet without using setCellValue() to insert a formula in the first place?
[英]How find data from excel sheet based on user input
有什么办法可以从Excel工作表中查找特定用户的ID记录。 正在从表单输入用户ID,如果有人知道,请在下面回复我的代码
<!doctype>
<html>
<head>
</head>
<body>
<?php
require_once "Classes/PHPExcel.php";
$tmpfname = "test.xlsx";
$excelReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
$excelObj = $excelReader->load($tmpfname);
$worksheet = $excelObj->getSheet(0);
$lastRow = $worksheet->getHighestRow();
echo "<table>";
for ($row = 1; $row <= $lastRow; $row++) {
echo "<tr><td>";
echo $worksheet->getCell('A'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('B'.$row)->getValue();
echo "</td><tr>";
}
echo "</table>";
?>
</body>
</html>
请更好地阐明“查找”的含义。
无论如何,您已经在对象$ worksheet中包含了excel的内容,因此只需修改代码,您就可以执行以下操作:
$user_id_to_check="123456";
for ($row = 1; $row <= $lastRow; $row++) {
// Save the user_id value from excel
$user_id_from_excel=$worksheet->getCell('A'.$row)->getValue(); // assuming cell A store the user_id
// compare user_id
if ($user_id_to_check==$user_id_from_excel) {
// OK
} else {
// KO
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.