Iam正在处理excel导入应用程序。我尝试导入excel文件,但日期未存储在数据库中。其他文本字段被存储。
表结构
<?php
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;
require_once ('connect.php');
require_once ('Spout/Autoloader/autoload.php');
if(!empty($_FILES['excelfile']['name']))
{
// Get File extension eg. 'xlsx' to check file is excel sheet
$pathinfo = pathinfo($_FILES['excelfile']['name']);
// check file has extension xlsx, xls and also check
// file is not empty
if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
&& $_FILES['excelfile']['size'] > 0 )
{
$file = $_FILES['excelfile']['tmp_name'];
// Read excel file by using ReadFactory object.
$reader = ReaderFactory::create(Type::XLSX);
// Open file
$reader->open($file);
$count = 0;
// Number of sheet in excel file
foreach ($reader->getSheetIterator() as $sheet)
{
// Number of Rows in Excel sheet
foreach ($sheet->getRowIterator() as $row)
{
// It reads data after header. In the my excel sheet,
// header is in the first row.
if ($count > 0) {
// Data of excel sheet
$content = $row[1];
$title = $row[0];
$date = $row[2];
$language = $row[4];
$dt = $row[5];
$location = $row[3];
$new_date = date_format($date,'Y-m-d H:i:s');
$new_dt = date_format($dt,'Y-m-d H:i:s');
//Here, You can insert data into database.
$qry = "INSERT INTO `icn`(`icn_title`, `icn_content`,`icn_date`,`icn_location`, `icn_language`, `updated_on`) VALUES ('$title','$content
t',`$new_date`,'$location','$language',`$new_dt`)";
$res = mysqli_query($con,$qry);
}
$count++;
}
}
if($res)
{
echo "Your file Uploaded Successfull";
}
else
{
echo "Your file Uploaded Failed";
}
// Close excel file
$reader->close();
}
else
{
echo "Please Choose only Excel file";
}
}
else
{
echo "File is Empty"."<br>";
echo "Please Choose Excel file";
}
?>
将Excel工作表导入数据库后,$ new_date和$ new_dt字段为空。
这是我的Excel工作表格式
我尝试将类型用作icn_date和Updated_on字段的“文本”。但是仍然没有任何效果。