Results 1 to 2 of 2

Thread: Excel.Workbook Writing with Reference to Cell (i)

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    24

    Question Excel.Workbook Writing with Reference to Cell (i)

    I'm trying to export a list of properties received from an API call out to an excel workbook. I'm quite inexperienced in the area but I'm trying to have the properties written relative to the cell (i) in the for loop.

    The code is this at the moment:

    vb.net Code:
    1. Public Sub BHorse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHorse.Click
    2.         Dim oMarketsReq As New BFExchange.GetAllMarketsReq
    3.         Dim oMarketsResp As BFExchange.GetAllMarketsResp
    4.         With oMarketsReq
    5.             .header = oHeaderAU()
    6.             ReDim .eventTypeIds(0) : .eventTypeIds(0) = 7
    7.             ReDim .countries(1) : .countries(0) = "AUS" : .countries(1) = "USA"
    8.             .fromDate = Today
    9.             .toDate = Today.AddDays(1)
    10.         End With
    11.         oMarketsResp = BetfairAU.getAllMarkets(oMarketsReq)
    12.         With oMarketsResp
    13.             CheckHeader(.header)
    14.             Label6.Text = "ErrorCode = " & .errorCode.ToString
    15.             If .errorCode = BFExchange.GetAllMarketsErrorEnum.OK Then
    16.                 Dim AllMarkets As New UnpackAllMarkets(.marketData)
    17.                 Dim oWB As Excel.Workbook = moApp.Workbooks.Add
    18.                 With AllMarkets
    19.                     For i = 0 To .marketData.Length - 1
    20.                         With .marketData(i)
    21.                             Dim oSht As Excel.Worksheet = DirectCast(moApp.Workbooks.Add.Sheets("Sheet1"), Excel.Worksheet)
    22.                             oSht.Cells(1, 1) = .marketId & " " & .marketStatus & "  " & .marketName & "  " & .menuPath
    23.                             oSht.Cells(1, 2) = "the line is " & i
    24.                             oSht.Cells(3, 1) = "2"
    25.                             oSht.Cells(4, 1) = "4"
    26.                             oSht.Cells(7, 1) = "=SUM(A3, A4)"
    27.                             moApp.Visible = True
    28.                             moApp.Workbooks.Add.Close(True, "C:\Data\market.xls")
    29.                             oSht = Nothing
    30.                             oWB = Nothing
    31.                         End With
    32.                     Next
    33.                 End With
    34.             End If
    35.         End With
    36.     End Sub


    This code runs with no errors but it creates a new workbook for each entry whereas I want all the data in the single workbook C:\Data\market.xls .

    When I change
    vb.net Code:
    1. oSht.Cells(1, 1)
    to
    vb.net Code:
    1. oSht.Cells(i, i)
    I receive errors.
    Last edited by Snurry; Jan 30th, 2010 at 05:08 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width