【发布时间】:2011-09-28 00:10:51
【问题描述】:
我可以将现有表/视图的结果链接到 Excel 电子表格(通过从 ODBC 向导的“选择数据库和表”窗口中选择表,但是我想改为执行原始查询。
我想根据单元格值生成一个查询(作为字符串)。然后,用户可以手动“刷新”数据表,将当前字符串发送到 Oracle 并返回结果。
有没有办法将原始查询 (DML) 的结果链接到 Excel 电子表格?
【问题讨论】:
我可以将现有表/视图的结果链接到 Excel 电子表格(通过从 ODBC 向导的“选择数据库和表”窗口中选择表,但是我想改为执行原始查询。
我想根据单元格值生成一个查询(作为字符串)。然后,用户可以手动“刷新”数据表,将当前字符串发送到 Oracle 并返回结果。
有没有办法将原始查询 (DML) 的结果链接到 Excel 电子表格?
【问题讨论】:
将数据库表链接到电子表格后,您可以使用宏来执行此操作。假设您的链接表从单元格 A1 开始:
' Build your query string - using whatever cell values you need
sqlQuery = "select * from myTable"
' Get the cursor on the top left cell of the existing linked table
Range("A1").Select
' Set the CommandText of that QueryTable to your new query and refresh it
With Selection.QueryTable
.CommandText = sqlQuery
.Refresh BackgroundQuery:=False
End With
试试看……
【讨论】:
您必须设置查询,然后在查询中创建一个参数来限制结果集。通常,然后您让该查询填充一个新工作表。系统将提示您输入参数的值。将其设置为单元格引用,并选中复选框以自动重新查询该单元格是否更改。
【讨论】: