خواندن اطلاعات xlsx در php ساده
برای خواندن اطلاعات از یک فایل xlsx در PHP، می توانید از کتابخانه PHPExcel استفاده کنید. این کتابخانه قابلیت خواندن و نوشتن فایل های Excel را در PHP فراهم می کند.
برای خواندن اطلاعات از یک فایل xlsx، می توانید از کد زیر استفاده کنید:
include 'PHPExcel/IOFactory.php';
$inputFileName = 'example.xlsx';
// Create a new Reader of the type Excel2007
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
// Load the file
$objPHPExcel = $objReader->load($inputFileName);
// Select the first worksheet
$worksheet = $objPHPExcel->getActiveSheet();
// Get the highest row and column numbers used in the worksheet
$highestRow = $worksheet->getHighestRow();
$highestColumn = $worksheet->getHighestColumn();
// Loop through each row of the worksheet
for ($row = 1; $row <= $highestRow; $row++) {
// Loop through each column of the row
for ($col = 'A'; $col <= $highestColumn; $col++) {
// Get the cell value
$cellValue = $worksheet->getCell($col.$row)->getValue();
// Do something with the cell value
echo $cellValue;
}
}
در این کد، فایل xlsx با استفاده از کتابخانه PHPExcel خوانده شده و اطلاعات آن در حلقه های داخلی بازیابی و پردازش می شوند. پس از بازیابی هر سلول، می توانید با آن به هر شیوه دیگری که مورد نیاز است، کار کنید.
原文地址: https://www.cveoy.top/t/topic/CVu 著作权归作者所有。请勿转载和采集!