åå¤å·¥ä½ï¼ ä¸è½½PHP-ExcelReaderï¼ä¸è½½åç¨å°\phpExcelReader\Excelç®å½ä¸çoleread.incåreader.php两个æ件ï¼å¹¶å°reader.phpæ件æå¼årequire_once 'Spreadsheet/Excel/Reader/OLERead.php';å±è½æï¼å¢å 为require_once 'oleread.inc'; ç¶åç´æ¥å°è¿ä¸¤ä¸ªæ件å¤å¶å°æå¡å¨ä¸WAMP,ç´æ¥å¤å¶å°WWWç®å½ä¸ï¼åå°æéè¦çexcelæ件èè¿æ¥æçæ件æ¯classify.xlsï¼ç¶åéè¦ä¸ä¸ªè°ç¨reader.phpçæ件ï¼æºä»£ç å¦ä¸ï¼
ExcelToMysql.php
<?php
require_once 'reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('gbk');
$data->read('classify.xls'); //âclassify.xlsâæ¯æè¦å¯¼å
¥å°mysqlä¸çexcelæ件
@ $db = mysql_connect("localhost", "root", "") or
die("Could not connect to database.");//è¿æ¥æ°æ®åº
mysql_query("set names 'gbk'");//è¾åºä¸æ
mysql_select_db('japlearn'); //éæ©æ°æ®åº
error_reporting(E_ALL ^ E_NOTICE);
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
//以ä¸æ³¨éçfor循ç¯æå°excel表æ°æ®
//以ä¸ä»£ç æ¯å°excel表æ°æ®ã6个å段ãæå
¥å°mysqlä¸ï¼æ ¹æ®ä½ çexcel表å段çå¤å°ï¼æ¹å以ä¸ä»£ç å§ï¼
$sql = "INSERT INTO classify VALUES('".
$data->sheets[0]['cells'][$i][1]."','".
$data->sheets[0]['cells'][$i][2]."','".
$data->sheets[0]['cells'][$i][3]."','".
$data->sheets[0]['cells'][$i][4]."','".$data->sheets[0]['cells'][$i][5]."','".$data->sheets[0]['cells'][$i][6]."')";
echo $sql.'<br />';
$res = mysql_query($sql);
}
?>
æä¸é¢ä»£ç 注éçå°æ¹æ¿æ¢æèªå·±é
置好çæ°æ®ï¼å¦æ°æ®åºé
ç½®çãè¿è¡æ¬æºæµè¯å°åå®ç°å¯¼å
¥ã
温馨提示:内容为网友见解,仅供参考