使用C++处理WebQuery类型的外部数据连接

使用 WebQuery 类型的外部数据连接

以下代码显示了如何处理类型为 WebQuery 的外部数据连接。它使用了您可以从提供的链接下载的 示例 Excel 文件。您还可以在下文看到此代码的控制台输出。

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;
using namespace Aspose::Cells::ExternalConnections;

int main()
{
    Aspose::Cells::Startup();

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Path of input excel file
    U16String inputFilePath = srcDir + u"WebQuerySample.xlsx";

    // Create workbook
    Workbook workbook(inputFilePath);

    // Get the first external connection from the workbook
    ExternalConnection connection = workbook.GetDataConnections().Get(0);

    // Check if the connection is a WebQueryConnection
    if (connection.GetClassType() == ExternalConnectionClassType::WebQuery)
    {
        // Cast to WebQueryConnection
        WebQueryConnection webQuery(connection);

        // Print the URL of the web query
        std::cout << "Web Query URL: " << webQuery.GetUrl().ToUtf8() << std::endl;
    }

    Aspose::Cells::Cleanup();
}

控制台输出

这是上述代码与此 示例 Excel 文件 的控制台输出。

Web Query URL: https://docs.aspose.com/cells/net/