我有一个包含 15 列和 248 行的 excel 文件。我想将此excel文件数据插入数据库。为此,我选择 PHPExcel 脚本。使用此脚本,我已成功将 14 列数据插入到数据库表中。但是每个单元格中的 html 标记或代码中包含 15 列名称“描述”。当我尝试沿其他 14 列上传它时,只插入了 92 条记录而不是 248 条。没有 15 列,其他人成功插入 248 行。我正在分享我的代码,让我知道问题出在哪里。谢谢
>include($HTTP_SERVER_VARS["DOCUMENT_ROOT"]."/my_session.php");<br>
>require_once($HTTP_SERVER_VARS["DOCUMENT_ROOT"]."/includes/Classes/PHPExcel/IOFactory.php");
>$filetype = $_FILES["file"]["type"];<br>
$filename = $_FILES["file"]["name"];<br>
$filetmp = $_FILES["file"]["tmp_name"];<br>
$Ext = strrchr($filename,".");<br>
//set_time_limit(3000);
>$objReader = new PHPExcel_Reader_CSV();<br>
$objPHPExcel = $objReader->load("ebay.csv");<br>
>foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {<br>
$worksheetTitle = $worksheet->getTitle();<br>
$highestRow = $worksheet->getHighestRow(); <br>
$highestColumn = $worksheet->getHighestColumn(); <br>
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);<br>
$nrColumns = ord($highestColumn) - 64; <br>
>for ($row=2; $row<=$highestRow; $row++) {<br>
$item_name = $worksheet->getCellByColumnAndRow(3, $row)->getValue();<br>
$condition = $worksheet->getCellByColumnAndRow(4, $row)->getValue();<br>
$Category = $worksheet->getCellByColumnAndRow(7, $row)->getValue();<br>
$Quantity = $worksheet->getCellByColumnAndRow(11, $row)->getValue();<br>
$StartPrice = $worksheet->getCellByColumnAndRow(14, $row)->getValue();<br>
$BuyItNowPrice = $worksheet->getCellByColumnAndRow(15, $row)->getValue();<br>
$Duration = "365";<br>
$ItemID = $worksheet->getCellByColumnAndRow(29, $row)->getValue();<br>
$objPHPExcel->getActiveSheet()->getCell('A1')->getValue();<br>
$PostageServices1 = $worksheet->getCellByColumnAndRow(95, $row)->getValue();<br>
$PostageCost1 = $worksheet->getCellByColumnAndRow(96, $row)->getValue();<br>
$PostageServices2 = $worksheet->getCellByColumnAndRow(101, $row)->getValue();<br>
$PostageCost2 = $worksheet->getCellByColumnAndRow(102, $row)->getValue();<br>
$PostageServices3 = $worksheet->getCellByColumnAndRow(106, $row)->getValue();<br>
$PostageCost3 = $worksheet->getCellByColumnAndRow(107, $row)->getValue();<br>
$DispatchTimeMax = $worksheet->getCellByColumnAndRow(122, $row)->getValue();<br>
$ReturnsAcceptedOption = $worksheet->getCellByColumnAndRow(195, $row)->getValue();<br>
$AdditionalDetails = $worksheet->getCellByColumnAndRow(202, $row)->getValue();<br>
$item_description = stripslashes($worksheet->getCellByColumnAndRow(30, $row)->getValue());<br>
>insertInto("INSERT INTO mytable (`item_name`,`condition`,`Category`,`Quantity`,`StartPrice`,`BuyItNowPrice`,`Duration`,`item_code`,`PostageServices1`,`PostageCost1`,`PostageServices2`,`PostageCost2`,`PostageServices3`,`PostageCost3`,`DispatchTimeMax`,`ReturnsAcceptedOption`,`AdditionalDetails`) VALUES ('$item_name','$condition','$Category','$Quantity','$StartPrice','$BuyItNowPrice','$Duration','$ItemID','$PostageServices1','$PostageCost1','$PostageServices2','$PostageCost2','$PostageServices3','$PostageCost3','$DispatchTimeMax','$ReturnsAcceptedOption','$AdditionalDetails')");
}
}<br>
描述单元格包含 html 元素,即 table、p、b 字体等...每个 excel 单元格都很重,因此我需要适当的方法来处理 html。phpexcel中是否有任何函数或方法可以处理此html单元格数据并将其从excel中获取并从头到尾插入数据库?如果是,请给我至少一个例子。