[英]How can I export data from Excel to mysql?
此代码可以在personal.xlsb(MS Excel)上运行以将数据传输到mysql吗?
我得到空白行。
Public Sub Insert_Testing()
Dim con as adodb.connection
Dim lastrow as long
Set ws = ThisWorkbook.ActiveSheet
Set con = New Adodb.connection
Con.open = "Provider=MSDASQL.1;Data Source=MySQL_db;"
Dim rng as range
Lastrow = ws.Range("B" & Rows.count).End(x1Up).row
Set rng = ws.Range("A2:G" & Lastrow)
Dim row as range
For each row in rng.rows
SQL = "Insert into skynet_msa.ALU_testing (Area, Min_C, Max_C, Avg_C, Emis, Ta_C, Area_Px) values ('" & row.Cells(1).Value & '", '" & row.Cells(2).Value & '", '" & row.Cells(3).Value & '", '" & row.Cells(4).Value & '", '" & row.Cells(5).Value & '", '" & row.Cells(6).Value & '", '" & row.Cells(7).Value &'");"
Con.Execute SQL
Next row
Con.close
MsgBox "Done"
End Sub
这似乎不起作用,因为这里的活动表一直引用我的personal.xlsb,而不是我计划导出数据的其他文档,因为这两个文档同时打开。
我认为你需要改变这一点:
SQL = "Insert into skynet_msa.ALU_testing (Area, Min_C, Max_C, Avg_C, Emis, Ta_C, Area_Px) values ('" & row.Cells(1).Value & '", '" & row.Cells(2).Value & '", '" & row.Cells(3).Value & '", '" & row.Cells(4).Value & '", '" & row.Cells(5).Value & '", '" & row.Cells(6).Value & '", '" & row.Cells(7).Value &'");"
对此:
SQL = "Insert into skynet_msa.ALU_testing (Area, Min_C, Max_C, Avg_C, Emis, Ta_C, Area_Px) values ('" & row.Cells(1).Value & "', '" & row.Cells(2).Value & "', '" & row.Cells(3).Value & "', '" & row.Cells(4).Value & "', '" & row.Cells(5).Value & "', '" & row.Cells(6).Value & "', '" & row.Cells(7).Value & "');"
您的个人 xlsb 可能有其他干扰的功能/vba 代码。 我只是猜测。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.