连接到 SQL
我想添加一个到工作表的连接,以便每次刷新单元格时,都会从 SQL 传入一个值。我希望它引用其他工作表之一上的文本框,其中 ID =
如何设置连接以使用该值刷新。我应该在连接字符串中放入什么?我可以让它静态工作。
I want to add a connection to a sheet so that each time a cell is refreshed, a value is passed in from SQL. I want it to reference a textbox on one of the other sheets for where ID =
How do I set the connection to refresh with that value. What do I put in my connection string? I can get it to work staticly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Excel 有一个方便的小功能,称为“导入外部数据”。这是我要做的:
在 Excel 文件中,转到数据->导入外部数据->新数据库查询 (在您的情况下,“导入数据”选项不是最好的方法)
完成向导。选择您的数据源等。除最后一个选项外,请选择在 Microsoft Query 中查看数据或编辑查询
MS Query 基本上是一个小型查询设计器。选择显示/隐藏条件图标(看起来像眼镜+漏斗)。
这个用于输入条件的界面很像 Access。选择一个字段,而不是硬编码值,而是使用[Criteria](或其他内容)。
关闭 MS Query 并返回到 Excel 文件。
在新数据范围中,右键单击参数。->从以下单元格获取值
不要忘记单元格值更改时自动刷新
总而言之,您正在使用参数导入外部数据,并将该参数的值声明为文件中的单元格。嗯,这是我工作之余的一次愉快的休息。我希望这有帮助。
Excel has a handy little feature called "Import External Data". Here's what I would do:
In your Excel file, goto Data->Import External Data->New Database Query (In your case, the Import Data option won't be the best method)
Go through the wizard. Choose your datasource, etc. Except on the last option, choose View data or edit query in Microsoft Query
MS Query is basically a little query designer. Choose the show/hide criteria icon (looks like eyeglass + funnel).
This interface for putting in criteria is much like Access. Choose a field and instead of hard coding values, use [Criteria] (or something).
Close out MS Query and go back to the Excel file.
In your new data range, right-click to Parameters.->Get the value from the following cell
Don't forget the Refresh automatically when cell value changes
To summarize, you are importing external data using a parameter, and declaring the value of that parameter to be a cell in your file. Well, that was a nice little break from my own work. I hope this helps.
是什么导致细胞被刷新?连接字符串取决于您使用的数据库。下面的示例使用 Access 并需要引用 Microsoft ActiveX Dataobjects 2.8
数据放置在sheet1 上的单元格(1,1) 中。 where 子句取自sheet2 上的textbox1:
What causes the cell to be refreshed? The connection string will be dependent on what database you are using. The below example uses Access and needs a reference to Microsoft ActiveX Dataobjects 2.8
The data is put in cell(1,1) on sheet1. The where clause is taken from textbox1 on sheet2: