我正在尝试通过网页将 excel 2007 文件中的数据插入 mysql。我正在使用 phpexcel 库,但它无法工作..请帮助..我的代码看起来是这样的:我已经检查了每个地方,大多数代码都是这样的on;y 事情是我的数据库仍然是空的
<?php
//In case you want the script to be executed at a predefined time interval, use this
/*header('Refresh: 30'); */
//Establishing connection to Mysql Database:
$mysqli = new mysqli("localhost", "root","","final");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit(); }
//PHPEXCEL Reader
require 'includes/PHPExcel.php';
require_once 'includes/PHPExcel/IOFactory.php';
//action that happens when the button is pressed
if (isset($_POST['button1']))
{
echo "button on is pressed";
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] .
"You have not selected a file or some other error <br />";
}
else
{ // Errorless start
$inputFileName=$_FILES["file"]["name"];
$objPHPExcel = PHPExcel_IOFactory::load("C:/julisha/uploads/".$inputFileName);
// Creating a temporary copy on the server
$location="C:/wamp/www/julisha/uploads/"; // write the location on
// server where a copy should be created
move_uploaded_file($_FILES["file"]["tmp_name"],
$location . $_FILES["file"]["name"]);
//$inputFileName = $file_name;
$inputFileType = 'Excel2007';
$objReader = PHPExcel_IOFactory::createReader("$inputFileType");
$objReader->setReadDataOnly(true);
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
//Display Excel data on webpage
echo '<table>' . "\n";
for ($row = 1; $row <= $highestRow; ++$row) {
echo '<tr>' . "\n";
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
echo '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
//Preparing to import data from Excel to Mysql Database:
for($row = 2; $row <= $highestRow; ++$row) {
for($col = 0; $col < $highestColumnIndex; ++$col) {
$rows[$col] = $objWorksheet->getCellByColumnAndRow($col, $row);
}
$mysqli->query("INSERT INTO temp_results (Adm_No,Engl,Kis,Math,Chem) VALUES ('$rows[0]', '$rows[1]', '$rows[2]', '$rows[3]', '$rows[4]',)");
}
}
}
$mysqli->close();
?>
请帮忙