选中想要生成的列,套用表格格式,选中表包含标题的选项确定,然后在最右边的一列第二行处,点击函数功能,选择CONCATENATE,在文本里输入想要的结构即可
代码如下 | 复制代码 |
,=CONCATENATE("('",[@id],"','",[@name],"'),") |
这样生成的之后的语句可以写为
代码如下 | 复制代码 |
insert table1 (id,name) values ('1', "测试1"),('2', "测试2")... |
如果你会C#我们可以使用OleDb读取Excel并生成SQL语句
代码如下 | 复制代码 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Reflection; using Excel = Microsoft.Office.Interop.Excel; using System.Data; using System.Data.OleDb; using System.Windows.Forms; namespace ReadXlsxData { static class ParseXlsx { public static readonly int COMMENT_INDEX=4; //字段说明行下标 public static readonly int KEY_INDEX = 5; //主键行下标 public static readonly int TYPE_INDEX = 6; //字段类型行下标 public static readonly int SQLNAME_INDEX = 7; //数据库字段名行下标 public static readonly int VALUE_INDEX = 8; //value 行下标 public static StringBuilder objectData = new StringBuilder(); public static DataTable ToDataSet(string filePath) { string connStr = ""; string fileType = System.IO.Path.GetExtension(filePath); if (string.IsNullOrEmpty(fileType)) return null; if (fileType == ".xls") connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filePath + ";" + ";Extended Properties="Excel 8.0;HDR=NO;IMEX=1""; else connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filePath + ";" + ";Extended Properties="Excel 12.0;HDR=NO;IMEX=1""; string sql_F = "Select * FROM [{0}]"; OleDbConnection conn = null; OleDbDataAdapter da = null; DataTable dataTable = new DataTable(); try { // 初始化连接,并打开 www.111cn.net conn = new OleDbConnection(connStr); conn.Open(); da = new OleDbDataAdapter(); da.SelectCommand = new OleDbCommand(String.Format(sql_F, "Sheet1$"), conn); da.Fill(dataTable); } catch (Exception ex) { } } } |
}
最终导出结果如下