1
我不得不Excel文件記錄上傳到mysql
,我寫了下面的代碼是工作的罰款...的Excel到MySQL使用PHP
<?php
ini_set("display_errors",1);
require_once 'excel_reader2.php';
require_once 'db.php';
$data = new Spreadsheet_Excel_Reader("file.xls");
echo "Total Sheets in this xls file: ".count($data->sheets)."<br /><br />";
$html="<table border='1'>";
for($i=0;$i<count($data->sheets);$i++) // Loop to get all sheets in a file.
{
if(count($data->sheets[$i][cells])>0) // checking sheet not empty
{
echo "Sheet $i:<br /><br />Total rows in sheet $i ".count($data->sheets[$i][cells])."<br />";
for($j=1;$j<=count($data->sheets[$i][cells]);$j++) // loop used to get each row of the sheet
{
$html.="<tr>";
for($k=1;$k<=count($data->sheets[$i][cells][$j]);$k++) // This loop is created to get data in a table format.
{
$html.="<td>";
$html.=$data->sheets[$i][cells][$j][$k];
$html.="</td>";
}
$Productcode = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][1]);
$Artikel = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][2]);
$EANcode = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][3]);
$url_kiesk_nl = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][4]);
$query = "insert into test(Productcode,Artikel,EANcode,url_kiesk_nl) values('".$Productcode."','".$Artikel."','".$EANcode."','".$url_kiesk_nl."')";
mysqli_query($connection,$query);
$html.="</tr>";
}
}
}
$html.="</table>";
echo $html;
echo "<br />Data Inserted in dababase";
?>
現在我有一個單詞添加到了第4列每條記錄都寫了這條線。其實我的要求是給第四列的每個單元格添加「1」。
$url_kiesk_nl = mysqli_real_escape_string($connection,$data->"1".sheets[$i][cells][$j][4]);
但這不工作...任何人都可以請幫助我嗎?
感謝,但同時該表顯示第四列即將空白 – user3305327