在 SQL Server 中获取 Excel 工作表名称
如何使用 SQL Sever 2005 获取 Excel 文件中的工作表名称?
请注意:
- 没有前端(C#、VB、PHP等);
- 我试图仅使用 SQL Server 2005 来获取工作表名称。
谢谢。
How to get the sheet names in an Excel file using SQL Sever 2005?
Please be noted that:
- There is no front-end (C#, VB, PHP, etc.);
- I am trying to get the sheet names using nothing but SQL Server 2005 alone.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
至少有两种可能性可以做到这一点。我首先要承认,我没有一种简单的方法可以在 SQL Server 2005 中检查这一点,目前只有 2008 年。
1:创建链接服务器并使用
sp_tables_ex
和/或sp_columns_ex
:我找到了这个这里。
2:使用此处<所概述的 Ole 自动化程序/a>.我自己还没有尝试过这个。
There are at least two possibilities for doing this. I will admit up front that I don't have an easy way to check this in SQL Server 2005, only 2008 right now.
1: Create a linked server and use
sp_tables_ex
and/orsp_columns_ex
:I found the inspiration for this here.
2: Use Ole Automation Procedures as outlined here. I have not tried this one myself.
你不能。从 Excel 读取数据有两种途径。一种是 COM/OLE 自动化 路线,它允许您枚举工作簿中的工作表。这需要一种 TSQL 无法做到的过程语言。我什至不认为如果您允许混合使用 CLR 方法,您就无法访问 Office 库,因为它们不在 BCL 列表中。
在这种情况下,第二条路线是通过 openquery 使用 Jet 驱动程序,但作为设置的一部分,您需要明确定义要访问的文件和工作表。您可以放弃列出工作表名称,但即便如此,Excel 也不会根据我的猜测公开有关工作表的元数据。
如果有人知道另一种方法,我会删除这个答案,但通过多种方式分割这个问题,我还没有想出一个不能归结为上述两种方法之一的答案。
You can't. There are two routes to reading data from Excel. One is the COM/OLE automation route which would allow you to enumerate through worksheets in a workbook. That requires a procedural language which TSQL won't do. I don't even think if you allowed CLR methods into the mix, you'd be able to access the Office libraries as they aren't on the BCL list.
The second route would be to use the Jet driver via openquery in this case but as part of the setup, you need to explicitly define the file and worksheet to access. You can forgo listing the worksheet name but even then, Excel does not expose metadata about worksheets to the best of my divination.
I'll delete this answer if someone knows another way but having sliced this problem in a number of ways, I haven't come up with an answer that doesn't boil down to one of the two aforementioned approaches.
只是从 Tim 的答案中充实选项 2 - Ole 自动化程序,因为该链接现已失效。您可以使用如下代码来完成此操作:
Just fleshing out Option 2 - Ole Automation Procedures from Tim's answer, as the link for that is now dead. You can do this with code like the following: