douzuan5365 2010-09-25 20:32
浏览 37
已采纳

如何在php中将.xls文件加载到mysql数据库?

I want the exact opposite of this.

I want to load a .xls file full of emails into a database column.

What's the simplest way to do this?

  • 写回答

3条回答 默认 最新

  • douzi1350 2010-09-25 21:55
    关注

    Like Ponies said, you will have to first "Save As > CSV" then upload and do whatever. Often permissions will not allow that SQL statement however. My personal favorite is using csv2sql.com because it will do the heavy lifting and give you the SQL to just execute, however you could use fgetcsv which would be more secure, and something you can implement into a script.

    With fgetcsv, you could do something like this assuming you just had a one column file with the email addresses listed:

    $row = 1;
    if (($handle = fopen("test.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            //echo "<p> $num fields in line $row: <br /></p>
    ";
            $row++;
            for ($c=0; $c < $num; $c++) {
                if ($c==0){
                     //This is the first column
                     //Just run a generic MySQL insert command here (see below for link for more info on this)
                }
            }
        }
        fclose($handle);
    }
    

    Tutorial on PHP MySQL Insert: at W3Schools. That should get you going on this endeavor.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记