错误的输入数据PHPexcel

时间:2018-08-08 16:40:49

标签: php excel phpexcel

我正在尝试使用php将excel文件中的数据插入到我的数据库中,该excel文件是由我所在的公司提供的,我正在使用PHPexcel类,问题是当我从该文件几乎是不正确的,例如在第二列中有一个日期,但是当我显示它是一个数字时,在第三列中将“ E + 14”添加到值中

这是我导入文件的代码

try{$bdd = mysqli_connect("localhost", "root", "", "stage");}catch (Exception $e){die('Erreur : ' . $e->getMessage());}

$output = '';
if(isset($_POST["btn_upload"]))
{

 $extension = explode(".", $_FILES["upload_file"]["name"]); // For getting Extension of selected file
 $allowed_extension = array("xls", "xlsx", "csv"); //allowed extension
 if(in_array($extension[1], $allowed_extension)) //check selected file extension is present in allowed extension array
 {
  $file = $_FILES["upload_file"]["tmp_name"]; // getting temporary source of excel file
  include("Classes/PHPExcel/IOFactory.php"); // Add PHPExcel Library in this code
    $iniPrecision = ini_get('precision');
 $objPHPExcel    = PHPExcel_IOFactory::load($file);
 ini_set('precision', $iniPrecision); // create object of PHPExcel library by using load() method and in load method define path of selected file

  $output .= "<label class='text-success'>Data Inserted</label><br /><table class='table table-bordered'>";
  foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
  {
   $highestRow = $worksheet->getHighestRow();
   for($row=2; $row<=$highestRow; $row++)
   {$output .= "<tr>";
    $var1 = mysqli_real_escape_string($bdd, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
    $var2 = mysqli_real_escape_string($bdd, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
    $var3 = mysqli_real_escape_string($bdd, $worksheet->getCellByColumnAndRow(2, $row)->getValue());
   // $query = "INSERT INTO tbl_excel(excel_name, excel_email) VALUES ('".$name."', '".$email."')";
   // mysqli_query($connect, $query);
    $output .= '<td>'.$var1.'</td>';
    $output .= '<td>'.$var2.'</td>';
    $output .= '<td>'.$var3.'</td>';
    $output .= '</tr>';
   }
  } 
  $output .= '</table>';

0 个答案:

没有答案