0

I would like to add the returns of a json to excel cell by cell, like

2003-1  2003-2  2003-3  2003-4  2003-5  2003-6  2003-7  2003-8  2003-9 ....
number  number  number  number  number  number  number  number  number ....

Here is my code, but as can be understood it only pastes to the first cell, I could not construct the system I wanted. Thank you in advance..

    from xlwings import Workbook, Sheet, Range, Chart
    import requests
    import json

    payload = {'cityId':3969, 'lbDistricts':599, 'criter':149,'startdate':'2003-01','cmd':'result','areaCode':18439}
    url = "https://www.garantimortgage.com/apps/Socket/Webservice.ashx"
    r = requests.post(url, data=payload)

    wb = Workbook()
    data = json.loads(r.text)
    data = map(dict.values, data[u'output'][u'resultset'][u'record'][u'data'])
    for row in data:



Range("A1").value = '{:10}{:10}'.format(*row)

1 Answer 1

1

According to the doc's: "When assigning (nested) lists to a Range in Excel, it’s enough to just specify the top left cell as target address."

So you can just do (without iterating over the 2D list and assigning 1 row at a time):

Range("A1").value = data

Or if you want to transpose the list that be done with:

Range("A1").value = zip(*data)

I'm not sure what you're trying to do by formatting the strings, but hopefully that wasn't a part of your issue.

http://docs.xlwings.org/datastructures.html#lists

Sign up to request clarification or add additional context in comments.

1 Comment

Yes solved the problem! thank you, i will handle formatting the strings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.