DEF excel_to_json (): KEY_LIST = get_rows_value (0,1, + rows_total. 1 ) lan_list = get_col_value (0) del lan_list [0] # Deletion Key values are cell List = [] # List all languages stored inside the key pair for I in Range (. 1 , cols_total): list.append (dict (ZIP (KEY_LIST, get_rows_value (I, . 1, rows_total +. 1 )))) dict_temp = dict (ZIP (lan_list, List)) for K, V in dict_temp.items (): filename = K + ' .json ' with Open (filename,"w", encoding='utf-8') as f: json.dump({k: v},f,indent=2,ensure_ascii=False)
Relatively common method, the value read excel inside, then two merged into a dictionary, then the dictionary will convert into Json
Today encountered two problems:
1. combined into a dictionary, the dictionary traversal problem. Check some API, solutions are too complex, so do the East West to engage in export Json has a problem, and finally by {k: v} a combination of new dictionary way to solve this problem, this is the first use In this way, mark it
2. Open the file, parameterization of the file name, can not be parameterized in with.open inside, but you can use the filename as a variable defined outside the filename can