我正在使用下面的代码在 php 中的 mysql 中上传 excel 和 INSERT
public function read_file($table = 'users', $filename = 'test.xls') {
$this->load->library('Spreadsheet_Excel_Reader');
//$data = new Spreadsheet_Excel_Reader($pathToFile);
$data = new Spreadsheet_Excel_Reader();
$data->read($filename);
$sql = "INSERT INTO $table (";
for($index = 1;$index <= $data->sheets[0]['numCols']; $index++){
$sql.= strtolower($data->sheets[0]['cells'][1][$index]) . ", ";
}
$valuesSQL = '';
$sql = rtrim($sql, ", ")." ) VALUES ( ";
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$valuesSQL .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\"";
if($j!=$data->sheets[0]['numCols']){
$valuesSQL .= ",";
}
}
if($i!=$data->sheets[0]['numRows']){
$valuesSQL .= "),(";
}else{
$valuesSQL .= ")";
}
}
$sqlQuery = $sql . rtrim($valuesSQL);
return($sqlQuery );
}
我得到以下错误
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 3
Filename: controllers/userInfo.php
Line Number: 154
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 3
Filename: controllers/userInfo.php
Line Number: 154
我正在使用 codeigniter php 框架。
行号 154 ->$valuesSQL .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\"";