使用PHPExcel库读取Excel文件并将数据传输到数据库中
// Include PHPExcel_IOFactoryinclude 'PHPExcel/IOFactory.php';$inputFileName = './sampleData/example1.xls';// Read your Excel workbooktry { $inputFileType = PHPExcel_IOFactory::identify($inputFileName); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName);} catch(Exception $e) { die('Error loading file "'.pathinfo($inputFileName,PATHINFO_baseNAME).'": '.$e->getMessage());}// Get worksheet dimensions$sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn();// Loop through each row of the worksheet in turnfor ($row = 1; $row <= $highestRow; $row++){ // Read a row of data into an array $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE); // Insert row data array into your database of choice here}
一切都变得非常取决于您的数据库以及如何在其中构造数据
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)