#! /usr/bin/env python # -*- coding: utf-8 -*- from collections import OrderedDict import json, re, xlrd, codecs def write_xls_json(): """把xls转换成json""" wb = xlrd.open_workbook('./position.xls') convert_list = [] sh = wb.sheet_by_index(0) title = sh.row_values(0) for rownum in range(1, sh.nrows): rowvalue = sh.row_values(rownum) single = OrderedDict() for colnum in range(0, len(rowvalue)): print(title[colnum], rowvalue[colnum]) single[title[colnum]] = rowvalue[colnum] convert_list.append(single) j = json.dumps(convert_list) with codecs.open('./count_position.json', "w", "utf-8") as f: print json.dumps(j, ensure_ascii=False).encode('utf-8') f.write(json.dumps(j, ensure_ascii=False).encode('utf-8')) def read_json(): """读取json数据""" f = open("./count_position.json") setting = json.load(f) return setting write_xls_json()
Python=====1
猜你喜欢
转载自blog.csdn.net/a289237642/article/details/82384954
今日推荐
周排行