MySQL 如何使用phpmyadmin将Excel文件导入mysql数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16330242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:31:13  来源:igfitidea点击:

How to import Excel file into mysql database using phpmyadmin

mysqlexcelphpmyadminspreadsheet

提问by Chieftaind

I want to import from excel sheet format (.xls) to mysql database through phpmyadmin importing option. I understand that we need to convert the format to csv format first before we can import to the phpmyadmin. But unfortunately if I change to csv some special character or symbol will become question mark (?) or other different character/symbol. Please advise me on this as I am really new to phpmyadmin.

我想通过 phpmyadmin 导入选项从 excel 表格格式 (.xls) 导入到 mysql 数据库。我知道我们需要先将格式转换为csv格式,然后才能导入到phpmyadmin。但不幸的是,如果我更改为 csv,某些特殊字符或符号将变成问号 (?) 或其他不同的字符/符号。请就此给我建议,因为我对 phpmyadmin 真的很陌生。

Thanks

谢谢

回答by sravis

I have answered similary question here https://stackoverflow.com/a/16330428/1570901

我在这里回答了类似的问题https://stackoverflow.com/a/16330428/1570901

If you are familiar with html and php, by using this simply librarysimplex excel library and script you can create your own excel import to mysql. IT may take few minutes to create but once your create you can use it for life time.

如果您熟悉 html 和 php,通过使用这个简单的库simplex excel 库和脚本,您可以创建自己的 excel 导入到 mysql。创建它可能需要几分钟时间,但一旦创建,您就可以终生使用它。

// CREATE A HTML FORM TO UPLOAD EXCEL SHEET

// 创建一个 HTML 表单来上传 EXCEL 表

// THEN CREATE A PHP SCRIPT LIKE BELOW

// 然后创建一个像下面这样的 PHP 脚本

require 'simplexlsx.class.php';

if (isset($_FILES['Filedata'])) {

$file = $_FILES['Filedata']['tmp_name']; // UPLOADED EXCEL FILE

$xlsx = new SimpleXLSX($file);

list($cols, $rows) = $xlsx->dimension();

foreach( $xlsx->rows() as $k => $r) { // LOOP THROUGH EXCEL WORKSHEET

$q = "INSERT INTO TABLENAME(COL1, COL2) VALUE(";
  $q .=  "'".mysql_escape_string($r[0])."', "; // EXCEL DATA
  $q .=  "'".mysql_escape_string($r[1])."', "; // EXCEL DATA
  $q .= ")";

  $sql = mysql_query($q);

    } // IF ENDS HERE
    } // FOR EACH LOOP
}