如何根据excel表生成sql的insert脚本
根据excel自带的vba宏进行操作
首先alt+F11
点击插入~模块
录取执行语句
Sub GenerateSQL()Dim lastRow As IntegerlastRow = Cells(Rows.Count, 1).End(xlUp).RowFor 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后的是要输出脚本的列
& _ 代表另起一行
最后执行
脚本就在所输出列了