0
有没有办法做到这一点?我在Excel中有6000行,需要几个月的时间才能将它导入到sql数据库中。如何从excel文件导出数据并导入到sql数据库?
例如有:列A和列B在Excel,我想将其导入到列A和列B到SQL表。
谢谢!
有没有办法做到这一点?我在Excel中有6000行,需要几个月的时间才能将它导入到sql数据库中。如何从excel文件导出数据并导入到sql数据库?
例如有:列A和列B在Excel,我想将其导入到列A和列B到SQL表。
谢谢!
这是一种通过VBA的方法,用于书籍数据库。只要您可以建立与数据库的连接,就不会太困难。显然,你必须稍微调整一下,以便它能够与你的数据库和你的数据一起工作。特别是,你将不得不调整SQL字符串来连接你的数据库(改变“test.yourdatabase”)
Sub addBook(title As String, author As String, link As String, foundBy As String)
' for this code to work, you need a reference to the MS Activex
' data access objects
' Tools|References... microsoft activex data objects 2.8 (or newer)
Dim cn As New Connection
Dim cs As String
Dim un as String
Dim pw as String
Dim sql As String
cs = "DRIVER=SQL Server;SERVER=websql.org,5901;DATABASE=websql" 'connection string
un = username 'this is the username for the database
pw = password 'this is the password for the database account
cn.Open cs, Range("un").Value, Range("pw").Value
sql = "insert into test.yourdatabase(searchtitle, searchAuthor, link, foundBy, foundTime) values(" & _
"'<TITLE>', " & _
"'<AUTHOR>', " & _
"'<LINK>', " & _
"'<FOUNDBY>', " & _
"getdate());"
'replace statements are for correcting any ' that occure in the titles or names
sql = Replace(sql, "<TITLE>", Replace(title, "'", "''"))
sql = Replace(sql, "<AUTHOR>", Replace(author, "'", "''"))
sql = Replace(sql, "<LINK>", Replace(link, "'", "''"))
sql = Replace(sql, "<FOUNDBY>", Replace(foundBy, "'", "''"))
'Debug.Print sql
cn.Execute sql
cn.Close
End Sub
Sugestion,保存Excel为CSV然后使用任何编程语言解析它变成可以插入 - >运行脚本! –
我知道微软Office Access有一个功能可以从excel工作表导入数据库。你可能想看看那 – Manuel
哪个数据库? MySQL,SQL Server,DB2?无论如何,首先导出所需的CSV格式数据(在Excel中,保存为.csv文件),然后将该CSV文件导入到数据库中。 (不同的数据库有不同的做法。) –