1

我是 php 新手。我需要在 php 中将 excel 详细信息导入 MySQL 数据库。我下载了 2 个文件reader.php&oleread.php并将其保存在wamp/www/folder. 当我执行以下代码时,服务器会抛出类似的错误

文件名 samp.xls 不可读

给出解决这个问题的解决方案。我的代码是:

<html>
  <head>
  <title>Save Excel file details to the database</title>
  </head>
  <body>
    <?php
        include 'db_connection.php';
        include 'reader.php';
        $excel = new Spreadsheet_Excel_Reader();
    ?>
        <table border="1">
        <?php
            $excel->read('samp.xls');
            $x=2;
            while($x<=$excel->sheets[0]['numRows']) {
                $id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
                $name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
                // Save details
                $sql_insert="INSERT INTO students (sid,name) VALUES ('$id','$name')";
                $result_insert = mysql_query($sql_insert) or die(mysql_error());
              $x++;
            }
        ?>
    </table>
  </body>
</html>
4

2 回答 2

0

为什么不直接将其导入phpmyadmin?点击这里

于 2013-07-15T06:17:06.917 回答
0

文件名 samp.xls 不可读

首先要想到的是您的 php 服务器无法读取您的 excel 文件..

WAMPWindows上,所以右键单击您的 excel 文件,然后将read属性添加到Everyone

于 2013-07-15T06:32:05.983 回答