我似乎无法让我的Excel工作簿(使用ADODB)与Excel Mac 2011一起使用。我使用的是ADODB代码。是否有可用的加载项?即使是来自第三方的?有没有人把这个弄好了?
发布于 2012-03-15 03:01:10
是否有可用的加载项?甚至来自第三方?
希望这些下载链接能有所帮助?
ODBC drivers that are compatible with Excel for Mac
引用自MSKB,以防链路中断
与 for Mac兼容的Excel驱动程序
如果要将数据从数据库导入Excel for Mac,则需要在Mac上安装开放式数据库连接(ODBC)驱动程序。您获得的驱动程序取决于您的Excel for Mac的版本。
适用于Mac2011的Excel
此版本的Excel不提供ODBC驱动程序。您必须自己安装它。以下公司提供了与Excel for Mac 2011兼容的驱动程序:
安装源代码的驱动程序后,可以使用Microsoft Query创建新查询或刷新在其他Excel版本中创建的现有查询,如Excel X、Excel 2004和Excel for Windows。有关详细信息,请参阅Import data from a database in Excel for Mac 2011。
适用于Mac的Excel2016
此版本的Excel提供了用于连接到SQL Server数据库的ODBC驱动程序。在Data选项卡上,单击New Database Query > SQL Server ODBC。然后使用对话框导入数据。
如果要连接到其他ODBC数据源(例如,Mac ),则需要在FileMaker上为数据源安装ODBC驱动程序。以下公司提供了与Excel for Mac兼容的驱动程序:
有没有人把这个弄好了?
对不起,我从来没有用过。
发布于 2014-08-05 04:19:44
在Mac Excel 2011中不支持ADODB,但ODBC可与第三方驱动程序配合使用。
我的ODBC驱动程序是从ActualTech得到的。下载并安装他们的程序,你就有了连接SQL服务器和数据库所需的驱动程序(免费试用,35美元购买)。
下面的代码创建与单元格数据库的连接,并将信息从数据库返回到mySQL A1中:
Dim connstring as String
Dim sqlstring as String
connstring = "ODBC;DRIVER={Actual Open Source Databases};" _
& "SERVER=<server_location>;DATABASE=<database>;" _
& "UID=<userID>;PWD=<password>;Port=3306"
sqlstring = "select * from <database_table>"
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=sqlstring)
.BackgroundQuery = False
.Refresh
End With发布于 2018-10-04 06:36:58
让Mac Excel查询MySQL有两个部分:(1) VBA和(2) ODBC驱动程序。
(1)用于从查询创建表(并使用新查询更新表)的VBA:
Option Explicit
Sub WaitQueryTableRefresh(ByVal qt As QueryTable)
While qt.Refreshing
Application.Wait (Now + TimeValue("0:00:01"))
Wend
End Sub
Sub ErrorIfQueryTableOverflowed(ByVal qt As QueryTable)
If qt.FetchedRowOverflow Then
err.Raise 5, "ErrorIfQueryTableOverflowed", _
"QueryTable '" & qt.ListObject.Name & "' returned more rows than can fit in the spreadsheet range"
End If
End Sub
' Create a table from scratch
Function CreateTableFromSql( _
ByVal table_sheet As Worksheet, _
ByVal table_range As Range, _
ByVal table_name As String, _
ByVal sql As String _
) As ListObject
' table_range is simply the top-left, corner cell for the table
'ListObject.SourceType
'https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.xllistobjectsourcetype?view=excel-pia
'QueryTable.CommandType
'https://docs.microsoft.com/en-us/office/vba/api/Excel.QueryTable.CommandType
'QueryTable.BackgroundQuery
'https://docs.microsoft.com/en-us/office/vba/api/excel.querytable.backgroundquery
'QueryTable.RefreshStyle
'https://docs.microsoft.com/en-us/office/vba/api/excel.xlcellinsertionmode
'QueryTable.PreserveColumnInfo
'https://stackoverflow.com/a/28621172
'https://docs.microsoft.com/en-us/office/vba/api/Excel.QueryTable.PreserveColumnInfo
Dim global_odbc_str As String
global_odbc_str = "ODBC;DSN=my_dsn_name;"
Dim qt As QueryTable
Set qt = table_sheet.ListObjects.Add( _
SourceType:=xlSrcExternal, _
Source:=global_odbc_str, _
Destination:=table_range _
).QueryTable
With qt
.ListObject.Name = table_name
.ListObject.DisplayName = table_name
.CommandText = sql
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.Refresh BackgroundQuery:=False
End With
Call WaitQueryTableRefresh(qt)
Call ErrorIfQueryTableOverflowed(qt)
Set CreateTableFromSql = qt.ListObject
End Function
' Update a table (columns do not have to be the same)
Sub UpdateTableFromSql( _
ByVal table As ListObject, _
ByVal sql As String _
)
Dim qt As QueryTable
Set qt = table.QueryTable
qt.CommandText = sql
qt.Refresh BackgroundQuery:=False
Call WaitQueryTableRefresh(qt)
Call ErrorIfQueryTableOverflowed(qt)
End Sub(2)配置MySQL ODBC驱动程序(免费)
根据MySQL docs进行安装
(a)安装(依赖项) iODBC管理员:http://www.iodbc.org/dataspace/doc/iodbc/wiki/iodbcWiki/Downloads
(b)安装MySQL ODBC驱动程序:https://dev.mysql.com/downloads/connector/odbc/
(c) Mac要求将所有应用程序(包括)隔离到沙箱。因此,您需要将MySQL驱动程序重新定位到Excel可以访问它的位置。执行此操作失败的症状是,在iODBC中,DSN连接将成功Test通,但在Excel的ODBC中将无法Test通。
根据this重新定位驱动程序
#!/bin/bash
# https://github.com/openlink/iODBC/issues/29
# https://bugs.mysql.com/bug.php?id=89931
base_src_dir="/usr/local"
mysql_odbc_name=$(ls "$base_src_dir" | grep -m 1 "mysql-connector-odbc")
odbc_dir="/Library/ODBC"
src="$base_src_dir/$mysql_odbc_name/lib"
dst="$odbc_dir/$mysql_odbc_name/lib"
echo "creating '$dst'"
sudo mkdir -p "$dst"
echo "copying '$src' to '$dst'"
sudo cp -af "$src/." "$dst"
odbc_ini_path="$odbc_dir/odbc.ini"
odbc_ini_bak_path="$odbc_ini_path.bak"
odbcinst_ini_path="$odbc_dir/odbcinst.ini"
odbcinst_ini_bak_path="$odbcinst_ini_path.bak"
echo "backing up '$odbc_ini_path' to '$odbc_ini_bak_path'"
sudo cp -f "$odbc_ini_path" "$odbc_ini_bak_path"
echo "backing up '$odbcinst_ini_path' to '$odbcinst_ini_bak_path'"
sudo cp -f "$odbcinst_ini_path" "$odbcinst_ini_bak_path"
# https://stackoverflow.com/a/29626460
function replace {
sudo sed -i '' "s/$(sed 's/[^^]/[&]/g; s/\^/\\^/g' <<< "$1")/$(sed 's/[&/\]/\\&/g' <<< "$2")/g" "$3"
}
ansi_driver=$(ls "$dst" | grep -m 1 "^lib.*a\.so$")
unicode_driver=$(ls "$dst" | grep -m 1 "^lib.*w\.so$")
old_ansi_path="$src/$ansi_driver"
new_ansi_path="$dst/$ansi_driver"
old_unicode_path="$src/$unicode_driver"
new_unicode_path="$dst/$unicode_driver"
echo "updating '$old_ansi_path' to '$new_ansi_path' in '$odbc_ini_path'"
replace "$old_ansi_path" "$new_ansi_path" "$odbc_ini_path"
echo "updating '$old_ansi_path' to '$new_ansi_path' in '$odbcinst_ini_path'"
replace "$old_ansi_path" "$new_ansi_path" "$odbcinst_ini_path"
echo "updating '$old_unicode_path' to '$new_unicode_path' in '$odbc_ini_path'"
replace "$old_unicode_path" "$new_unicode_path" "$odbc_ini_path"
echo "updating '$old_unicode_path' to '$new_unicode_path' in '$odbcinst_ini_path'"
replace "$old_unicode_path" "$new_unicode_path" "$odbcinst_ini_path"上面的测试是用Excel 2016在High Sierra上进行的。
https://stackoverflow.com/questions/9707256
复制相似问题