如何根据excel表生成sql的insert脚本 - 实践
根据excel自带的vba宏进行操作
开始alt+F11
点击插入~模块
录取执行语句
Sub GenerateSQL()
Dim lastRow As Integer
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastRow '假设第一行是标题
Cells(i, "S").Value = "INSERT INTO table_name (ID, RELEVANCE_ID, DATA_SOURCE, CREATE_DATE, MODIFY_DATE, DELETE_FLAG) VALUES ('" & _
Cells(i, "A").Value &
"', '" &
Cells(i, "B").Value &
"', '" &
Cells(i, "C").Value &
"', '" &
Cells(i, "D").Value &
"', '" &
Cells(i, "E").Value &
"', '" &
Cells(i, "F").Value &
"');"
Next i
End Sub
第一个Cells后的是要输出脚本的列
& _ 代表另起一行
最后执行
脚本就在所输出列了
浙公网安备 33010602011771号