使用 WebQuery 类型的外部数据连接
Contents
[
Hide
]
您可以使用 Workbook.DataConnections 集合访问任何类型的外部数据连接。其中一种数据连接类型是 WebQuery。本文将向您展示如何处理 WebQuery 数据连接。您可以使用 Microsoft Excel 中的 数据 > 来自网络 菜单创建 WebQuery 数据连接。
使用 WebQuery 类型的外部数据连接
以下代码显示了如何处理类型为 WebQuery 的外部数据连接。它使用了您可以从提供的链接下载的 示例 Excel 文件。您还可以在下文看到此代码的控制台输出。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "WebQuerySample.xlsx"); | |
ExternalConnection connection = workbook.DataConnections[0]; | |
if (connection is WebQueryConnection) | |
{ | |
WebQueryConnection webQuery = (WebQueryConnection)connection; | |
Console.WriteLine("Web Query URL: " + webQuery.Url); | |
} |
控制台输出
这是上述代码与此 示例 Excel 文件 的控制台输出。
Web Query URL: https://docs.aspose.com/cells/net/