• 133 views | 5 messages Discussion: LEAP
    Topic: Ii it possible to export all the results simultaneously to an excel sheet?Subscribe | Previous | Next
  • John Sanchez 11/17/2021

    1 Like

    Greetings

    I want to know if is there a way to export all the results without clicking on the results section?. An option to export all the results simultaneously just like the function that exports all the data that was entered into LEAP (Export to Excel).
  • Timothy Tibesigwa 11/19/2021
      Best Response

    Hello John

    Check out that link. Hope it will be of help

    Brgds


  • Charlie Heaps 11/19/2021
      Best Response

    Hi John,

    I'm afraid there is no single function to export all results to Excel. It would be a bit tricky to do that since different result types have different dimensions (e.g. some vary by fuel, others by pollutant, some are time-sliced, others annual etc.). However, you could write a script to largely automate this... Below is a simple example of how to start doing this by looping through all branches, and their results variables for all regions, scenarios and years.

    The code below can be run in LEAP's Script editor and it just prints to the screen, but you could adjust it to save results to a text file in CSV format or to export directly into Excel. You may also want to play with the ValueRS function. See this page for more info.

    You can add a filter to that to select results for particular fuels or pollutants. You could add loops to deal with each of these (but again, watch out! Itwill be slow!). I'm afraid you cannot filter across all possible result variable dimensions (yet).

    Hope this helps!

    'VBScript Code for Printing Results==================================

    Dim B, Y, C, ResVal
    CLS 'Clears the print area
    C = 0 'A counter
    SET B = LEAP.ActiveBranch 'just exports current branch or you could use FOR B in LEAP.Branches - but slow!
    for each r in LEAP.Regions
    for each S in LEAP.Scenarios
    for each v in B.Variables
    if not v.IsData then 'Only print result variables - not data variables
    for y = LEAP.BaseYear to LEAP.EndYear Step 10 'only print every 10th year
    ResVal = V.ValueRS(R, S, Y) 'Get the result and then print it and its unit
    PRINT C & ", " & S.Name & ", " & R.Name & ", " & B.Name & ", " & V.Name & ", " & Y & ", " & ResVal & ", " & V.DefaultResultUnit.Abbreviation
    C = C+1
    next 'y
    end if
    next 'v
    next 's
    next 'r

    TestLoop.png
  • Xiaoxuan Zhang 12/3/2021
      Best Response

    Hi Charles,

    Thanks for you reply. This is really helpful.But I want to know is it possible to exports all the branches by adding other loops and how should I add these loops?

    Erica
  • Charlie Heaps 12/12/2021
      Best Response

    Yes - see the comment in the code I provided. You just need to loop through all LEAP.Branches - but bear in mind this will be very slow!

    Charlie