|
之前通过VBA的ADO可以便捷进行EXCEL多工作簿和工作表访问,通过sql语句进行数据提取,转换到JSA经过亲测,可以如下实现:
1、可以到微软官方网站下载安装“2010版32位 Microsoft Access 数据库引擎 AccessDatabaseEngine.exe"
(“2010版64位、2016版64位”都不行,“2016版32位 [未测试]”如果电脑上安装了office64位应用,提示无法安装)。
2、建立xlsm文件,打开WPS - 开发工具 - WPS宏编辑器,示例代码如下:
function 单工作簿单工作表获取数据(){
let sqlstring = "SELECT * FROM [Sheet1$]"
let connstring = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\\Users\\whw\\Desktop\\bbb.xlsx;Mode=Share Deny Write;Extended Properties='HDR=YES; ';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Database Password='';Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password='';Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False"
let qtadd = ActiveSheet.QueryTables.Add(connstring,Range("c4"),sqlstring)
qtadd.Refresh()
}
function 多工作簿多工作表获取数据(){
let sqlstring = "select a.*,b.* from [Excel 12.0;Database=C:\\Users\\whw\\Desktop\\aaa.xlsx].[Sheet1$] as a left join [Excel 12.0;Database=C:\\Users\\whw\\Desktop\\bbb.xlsx].[Sheet1$] as b on a.[id]=b.[id] "
let connstring = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\\Users\\whw\\Desktop\\bbb.xlsx;Mode=Share Deny Write;Extended Properties='HDR=YES; ';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Database Password='';Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password='';Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False"
let qtadd = ActiveSheet.QueryTables.Add(connstring,Range("c4"),sqlstring)
qtadd.Refresh()
}
|
|