赞
踩
- import xlrd
-
- def read_xls(filename):
-
- # 打开Excel文件
- data = xlrd.open_workbook(filename)
-
- # 读取第一个工作表
- table = data.sheets()[0]
-
- # 统计行数
- rows = table.nrows
-
- data = [] # 存放数据
-
- time = 40
-
- for v in range(1, rows):
- values = table.row_values(v)
-
- # my_time = str(values[4])
- # print(my_time)
- # hour = my_time.split(":")
- # # min = hour[1].split("分")
- # # new_min = min[0].split(":")
- # #
- # print(hour)
- # time_count = int(int(hour[0]) * 60 + int(int(hour[1])+1))
-
- data.append(
- (
- {
- "identity":str(values[0]),
- "platform":str(values[1]), # 这里我只需要字符型数据,加了str(),根据实际自己取舍
- "drama_title":str(values[2]),
- "episode":str(values[3]),
- "time": str(values[4])
- }
- )
- )
-
- return data
-
- if __name__ == '__main__':
-
- d1 = read_xls("/Users/chenzhou/Desktop/my.xls")
-
- d2 = str(d1).replace("\'", "\"") # 字典中的数据都是单引号,但是标准的json需要双引号
- print(d2)
- # d2 = "{\"DeviceList\":" + d2 + "}" # 前面的数据只是数组,加上外面的json格式大括号
- # 可读可写,如果不存在则创建,如果有内容则覆盖
- jsFile = open("/Users/chenzhou/Desktop/my.json", "w+", encoding='utf-8')
- jsFile.write(d2)
- jsFile.close()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。