JSON to Excel Python

Source: Internet
Author: User

Specific parameters adjusted according to the actual situation

1 #-*-coding:utf-8-*2 ImportJSON3 ImportXLWT4 ImportOS5 ImportSYS6 7 Reload (SYS)8Sys.setdefaultencoding ('Utf-8')9dir = OS.GETCWD (). Decode ('Utf-8')TenDirlist =Os.listdir (dir) One Printdirlist A  -  - defReadjson (): thes = [] -      forFileinchdirlist: -         if ". JSON" inchFile: -With open (file,'R') as FR:#To open a file with +data = Json.load (FR)#use the Load method in JSON to convert the JSON string into a dictionary -S.append (data)#Save all dictionaries to the list +     returns A  at  - defWriteexcel (J): -Workbook = xlwt. Workbook (encoding='Utf-8') -Booksheet = Workbook.add_sheet ('Sheet', cell_overwrite_ok=True) -Rvalue =J -     #Print Rvalue intitle = [] -      forKvinchEnumerate (rvalue[0]): to Title.append (v) + booksheet.write (0, K, v) -     Printtitle the  *      forAinchRange (len (rvalue)): $          forBinchRange (len (title)):Panax Notoginseng             Try: -D =Title[b] thec =str (rvalue[a][d]) +                 #if C: ABooksheet.write (A + 1, B, c) the                 #Else: +                 #if c = = ': -                 #Booksheet.write (A + 1, B, ' {} ') $                 #Else: $                 #Booksheet.write (A + 1, B, ' {} ') -             except: -Booksheet.write (A + 1, B,"') theWorkbook.save (U'Merge'+'. xls') - Wuyi  the if __name__=='__main__': -QQQ = Json.dumps (Readjson () [0], encoding="UTF-8", ensure_ascii=False) WuWriteexcel (Readjson () [0])

JSON to Excel Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.