简体   繁体   English

从Excel查询MySQL数据(反之亦然)

[英]Query MySQL data from Excel (or vice-versa)

I'm trying to automate a tedious problem. 我正在尝试自动化一个繁琐的问题。 I get large Excel (.xls or .csv, whatever's more convenient) files with lists of people. 我得到了带有人员列表的大型Excel文件(.xls或.csv,更方便)。 I want to compare these against my MySQL database.* 我想将它们与我的MySQL数据库进行比较。*

At the moment I'm exporting MySQL tables and reading them from an Excel spreadsheet. 目前,我正在导出MySQL表并从Excel电子表格中读取它们。 At that point it's not difficult to use =LOOKUP() and such commands to do the work I need, and of course the various text processing I need to do is easy enough to do in Excel. 到那时,使用= LOOKUP()和这样的命令来完成我需要的工作并不困难,当然,我需要做的各种文本处理也很容易在Excel中完成。

But I can't help but think that this is more work than it needs to be. 但是我不禁认为这是需要做的工作。 Is there some way to get at the MySQL data directly from Excel? 有什么方法可以直接从Excel获取MySQL数据吗? Alternately, is there a way I could access a reasonably large (~10k records) csv file in a sql script? 或者,有没有一种方法可以在sql脚本中访问相当大(约10k记录)的csv文件?

This seems to be rather basic, but I haven't managed to make it work so far. 这似乎很基本,但是到目前为止我还没有设法使它工作。 I found an ODBC connection for MySQL but that doesn't seem to do what I need. 我找到了MySQL的ODBC连接,但这似乎并不能满足我的需要。

  • In particular, I'm testing whether the name matches or whether any of four email addresses match. 特别是,我正在测试名称是否匹配或四个电子邮件地址是否匹配。 I also return information on what matched for the benefit of the next person to use the data, something like "Name 'Bob Smith' not found, but 'Robert Smith' matches on email address robert.smith@foo". 我还会返回有关匹配内容的信息,以利于下一个人使用该数据,例如“找不到名称'Bob Smith',但是'Robert Smith'匹配电子邮件地址robert.smith@foo”。

You can use ADO and SQL. 您可以使用ADO和SQL。 This example is an insert query, but any query will work: 此示例是一个插入查询,但是任何查询都可以使用:

Excel VBA: writing to mysql database Excel VBA:写入mysql数据库

Why don't you load your CSV data into a dedicated table and perform your searches using MySQLs functions? 为什么不将CSV数据加载到专用表中并使用MySQLs函数执行搜索?
You could even do the logic from within excel (VBA or dotNET, depending on release) 您甚至可以从excel(VBA或dotNET,取决于发行版)中执行逻辑

No matter what you do, you will have to write a bunch of code, if you wan't to detect Robert Smith... 无论您做什么,都将不得不编写一堆代码,如果您不想检测罗伯特·史密斯...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM