excel - Mac 中 Excel 工作表的 Sql 查询

标签 excel vba macos oledb

这个问题在这里已经有了答案:





Is there a way to get ADODB to work with Excel for Mac 2011?

(3 个回答)


5年前关闭。




我已经通过 oledb 连接在 Windows pc 上的 Excel 2016 中编写了一个宏。但它在我的 Mac 中不起作用。我怎么能运行这个?通常,在 Windows 中,您选择工具 > 引用并检查 oledb 连接,但 Excel Mac 中没有工具选项。我不知道代码在这里很重要,但无论如何我都会分享它。

Dim sorgu1 As String
Dim con As Object, rs As Object
    Set con = CreateObject("adodb.connection")
    Set rs = CreateObject("adodb.recordset")
    con.Open "provider=microsoft.ace.oledb.12.0;data source=" & _
    ThisWorkbook.FullName & ";extended properties=""Excel 12.0;hdr=yes"""

    makine = Sheets("Dashboard").Cells(2, 11).Value

    sorgu1 = "select [Resource Id], [Order No], Sum(([Bitim Zamani]-[Basl Zamani])*1440)" 'as Plansiz, Sum(([Bitim Zamani]-[Basl Zamani])*1440)as Planli, Sum([Qty]) as Uretim"
    sorgu1 = sorgu1 + " from [Data$] where [Resource Id] = " + "'" + makine + "'"
    sorgu1 = sorgu1 + "GROUP BY [Resource Id], [Order No], [Duru Kodu]"

    Set rs = con.Execute(sorgu1)
    Sheets("Dashboard").Range("B65536").End(3).Offset(1, 0).CopyFromRecordset rs
    Set rs = Nothing

最佳答案

您的代码使用后期绑定(bind)并且不需要“引用”,只要该库在机器上可用。就您在 Mac OS 上的情况而言,该库不存在,据我所知,该库是明确不允许的。
From Microsoft (重点补充):

To import data from a database, such as Microsoft SQL Server, you must have an ODBC driver that is compatible with Microsoft Query installed on your computer. Compatible ODBC drivers are available from third-party vendors. For more information, see ODBC drivers that are compatible with Excel for Mac. For more information about installing ODBC drivers, see Microsoft Query Help.


重要的是,对于您的问题,如果使用 Excel 2011 for Mac,则 Mac OS 明确不支持 OLE DB。

Excel 2011 for Mac cannot import data from OLE DB or OLAP data sources.


所以,要回答你的问题,没有办法让你的 SQL 查询在 Mac 上工作,你需要完全使用其他东西。
但是,如前所述,如果您使用 Excel 2016 for Mac,您可以这样做:

This version of Excel does provide an ODBC driver for connecting to SQL Server Databases. On the Data tab, click New Database Query > SQL Server ODBC. Then use the dialog boxes to import the data.

If you are connecting to other ODBC data sources (for example, FileMaker Pro), then you'll need to install the ODBC driver for the data source on your Mac. Drivers that are compatible with Excel for Mac are available from these companies:


或者,这个类似问题的答案看起来很有希望:
https://stackoverflow.com/a/25126885/1467082

关于excel - Mac 中 Excel 工作表的 Sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40388545/

相关文章:

调用 GLeeInit() 给出 EXC_BAD_ACCESS

VBA Excel - 将字符串变量作为一行代码运行

Python xlrd 将整数和字符串转为 float

excel - 通过VBA为一列中的每个单元格添加符号

vba - 目录 vba- 仅可见工作表

ms-access - 在 MS Access VBA 中,如何使用参数调用存储的追加查询?

objective-c - 如何确定 NSButton 是否为复选框?

excel - 在“代理”接口(interface)+类中实现工作表的代码后,可以正确处理工作表事件

python - 有没有办法使用 Python 在 Excel 中执行类似 SQL 的 Select 语句?

SwiftUI 文本动画不透明度不起作用