-1

Possible Duplicate:
What is the easiest way to import an excel sheet into mysql

I would like to take an excel file and add the data contained in the file into a mysql database. This excel file is generated by lab software and the layout is customizable. However, I would like the data to be auto-transferred to the database without a user needing to log in or enter data manually. The lab software generates the excel sheet at the end of each sample analysis, and there is an option to run a command. I was transferring the data to a networked Access database, but now I am wanting this to be all web-based.

4

1 回答 1

0

您可以使用 LOAD DATA INFILE 将文件直接加载到 MySQL,但是您不能使用 excel 格式,但是如果您可以将该 excel 导出为 csv(大多数软件通常都支持,如果不可能,您可以使用在excel上另存为),那么它很容易使用。

LOAD DATA 命令的定义:

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
    [REPLACE | IGNORE]
    INTO TABLE tbl_name
    [FIELDS
        [TERMINATED BY 'string']
        [[OPTIONALLY] ENCLOSED BY 'char']
        [ESCAPED BY 'char' ]
    ]
    [LINES
        [STARTING BY 'string']
        [TERMINATED BY 'string']
    ]
    [IGNORE number LINES]
    [(col_name_or_user_var,...)]
    [SET col_name = expr,...)]

LOAD DATA INFILE 用法示例加载由 分隔并由 " 括起来的 csv

LOAD DATA INFILE 'myfile.csv'
    INTO TABLE tbl_name
    FIELDS
    ENCLOSED BY '"'
    TERMINATED BY ','
    LINES
    TERMINATED BY '\r\n'

更多信息在这里http://dev.mysql.com/doc/refman/5.0/es/load-data.html

于 2012-12-15T03:31:08.410 回答