|
楼主 |
发表于 2021-11-7 19:33
|
显示全部楼层
Excel可以一句SQL导入到SQLite的
- Sub SQLITE_INSERT_FROM_EXCEL_SQL()
- Rem 一次性将Excel数据添加到数据库
- Set SHX = Worksheets("数据")
- Rem INSERT INTO [表格名] ([栏位1],[栏位2], ...) SELECT [栏位1],[栏位2], ... FROM [表格名2]
- StrSQL = ""
- StrSQL = StrSQL & "INSERT INTO "
- Rem 联合查询的SQLite语句
- StrSQL = StrSQL & " [odbc;Driver={Devart ODBC Driver for SQLite};Database=" & ThisWorkbook.Path & "\SQLITEDB_01.db]"
- StrSQL = StrSQL & ".[人员信息表]" '//数据库内的数据表名
- StrSQL = StrSQL & " ([姓名],[体重],[出生日期],[年龄])" '//数据表的字段名
- Rem Excel的查询语句
- StrSQL = StrSQL & " SELECT [姓名],[体重],[出生日期],[年龄]"
- StrSQL = StrSQL & " FROM [数据$]" '//[数据$]" '//
-
- Str_coon = "Provider=Microsoft.Ace.OleDb.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties='Excel 12.0;HDR=YES';Persist Security Info=False;"
- INTX = AddDelMove(StrSQL, Str_coon)
-
- MsgBox "成功添加: " & INTX
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|