这里介绍一个直接将excel文件导入mysql的例子。我花了一晚上的时间测试,无论导入简繁体都不会出现乱码,非常好用。PHP-ExcelReader,下载地址: http://sourceforge.net/projects/phpexcelreader说明: 测试环境:MYSQL数据库采用utf8编码.导入EXCEL文档是xls格式,经过测试,xlsx 格式[excel 2007]也OK. 文中红色标注为需要注意的地方,请替换成你配置好的数据,如数据库配置等。运行http://localost/test.php实现导入。 以下是我贴出的详细代码,其中test.php为我写的测试文件,reader.php和oleread.inc文件是从上面提供的网址中下载的。 1. test.php代码如下:// getSmallBlockStream(PropertyStorage ps) $rootdata = $this->__readData($this->props[$this->rootentry]['startBlock']); $streamData = ''; $block = $this->props[$this->wrkbook]['startBlock']; //$count = 0; $pos = 0; while ($block != -2) { $pos = $block * SMALL_BLOCK_SIZE; $streamData .= substr($rootdata, $pos, SMALL_BLOCK_SIZE); $block = $this->smallBlockChain[$block]; } return$streamData; }else{ $numBlocks = $this->props[$this->wrkbook]['size'] / BIG_BLOCK_SIZE; if ($this->props[$this->wrkbook]['size'] % BIG_BLOCK_SIZE != 0) { $numBlocks++; } if ($numBlocks == 0) return ''; //echo "numBlocks = $numBlocks\n"; //byte[] streamData = new byte[numBlocks * BIG_BLOCK_SIZE]; //print_r($this->wrkbook); $streamData = ''; $block = $this->props[$this->wrkbook]['startBlock']; //$count = 0; $pos = 0; //echo "block = $block"; while ($block != -2) { $pos = ($block + 1) * BIG_BLOCK_SIZE; $streamData .= substr($this->data, $pos, BIG_BLOCK_SIZE); $block = $this->bigBlockChain[$block]; } //echo 'stream'.$streamData; return$streamData; } } } ?>登录后复制参考:http://hovertree.com/h/bjaf/to3l3tjm.htmhttp://www.cnblogs.com/roucheng/p/phpmysql.html 以上就介绍了PHP导入excel数据到MYSQL,包括了导入EXCEL,Mysql方面的内容,希望对PHP教程有兴趣的朋友有所帮助。 09-18 11:31