程序非常简单就是json转excel,直接运行py没有问题
#!/usr/bin/python3
-- coding:utf-8 --
import json
import tablib
import os
json.txt文件的格式: [{"a":1},{"a":2},{"a":3}]
path = os.path.abspath('.')
inpath = os.path.join(path,'json.txt')
outpath = os.path.join(path,'data.xls')
with open(inpath, 'r',errors='ignore') as f:
rows = json.load(f)
header=tuple([ i for i in rows[0].keys()])
data = []
for row in rows:
body = []
for v in row.values():
body.append(v)
data.append(tuple(body))
data = tablib.Dataset(*data,headers=header)
print (data[1])
open(outpath, 'wb').write(data.xls)
但是封装exe后总是会报‘Dataset’ object has no attribute ‘xls’
封装的方式一般使用pyinstall,其他方式也换过了,找的其他解决办法比如pip install tablib[all]之类的试了一个遍,还是没能解决