How can I perform a web query in C# similar to the Data > Import External Data > New Web Query in Mi

Posted by TNT on Stack Overflow See other posts from Stack Overflow or by TNT
Published on 2010-05-20T02:28:00Z Indexed on 2010/05/20 2:30 UTC
Read the original article Hit count: 302

Filed under:
|
|
|
|

I need to pull data from a table on a website. I can easily do this in VBA using the Web Query, but I need to do this in C#. I'm just having some trouble figuring out how to properly convert the code. I got something close, but it's returning HTML with the data. I just want the data. Any help would be great. The block of code giving me issues is below:

Private Function GetData(ByVal theURL As String, ByVal theRow As Integer, ByVal thePosition As Integer, ByVal theColumn As String, ByVal theTable As Integer) 

    With ActiveSheet.QueryTables.Add(Connection:="URL;" + theURL, Destination:=Sheet2.Range(theColumn & theRow + 1))  
        .Name = "op?s=" + Mid(theURL, thePosition + 1) + "_1"  
        .PreserveFormatting = True  
        .AdjustColumnWidth = True  
        .WebTables = theTable  
        .Refresh BackgroundQuery:=False  
    End With

End Function

© Stack Overflow or respective owner

Related posts about c#

Related posts about vba