import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import json
d = {"id": 1, "position": 3, "check_name": 2, "check_nums": 0}
with open("test.json", "w") as f:
json.dump(d, f)
from xlrd import open_workbook
import xlwt
workbook = open_workbook('./test3.xlsx')
sheet_name= workbook.sheet_names()
sheet = workbook.sheet_by_index(0)
print(sheet.name, sheet.nrows, sheet.ncols)
print(sheet.cell(0,0))
print(sheet.cell_value(0,0))
print(sheet.cell_value(0,1))
print(sheet.cell_value(0,2))
savedata = []
for key in range(sheet.nrows):
json_jpg={}
json_jpg["name1"] = sheet.cell_value(key,0)
json_jpg["name2"] = sheet.cell_value(key,1)
json_jpg["name3"] = sheet.cell_value(key,2)
json_jpg["name4"] = sheet.cell_value(key,3)
json_jpg["name5"] = sheet.cell_value(key,4)
json_jpg["name6"] = sheet.cell_value(key,5)
json_jpg["name7"] = sheet.cell_value(key,6)
json_jpg["name8"] = sheet.cell_value(key,7)
savedata.append(json_jpg)
with open("./saved.json", 'w') as filejson:
for tempjson in savedata:
json_str = json.dumps(tempjson, ensure_ascii=False)
filejson.write(json_str)
filejson.write('\n')
作者:知识在于分享