import xlrd
import os
def readxlsx(xlsxname,type):
out=""
if(type=="list"):
out = "[";
if(os.path.exists(r'.\xlsx\\'+xlsxname+'.xlsx')):
read_xlrd = xlrd.open_workbook(r'.\xlsx\\'+xlsxname+'.xlsx')
sheet1 = read_xlrd.sheet_by_index(0)
sheet2 = read_xlrd.sheet_by_index(1);
if(sheet2.nrows>1):
top = sheet2.row_values(0)
for num in range(1, sheet2.nrows):
row = sheet2.row_values(num)
out += "{"
for topnum in range(0, sheet2.ncols):
out += "\n"
out += top[topnum]
out += ":"
value = row[topnum]
value_type = sheet1.cell_value(topnum + 1, 1)
if (value_type == "string"):
out += "'"
if(isinstance(value,str)):
out += value
else:
out+=str(value)
out += "'"
elif (value_type == "num"):
out += str(value)
elif (value_type == "list"):
out += readxlsx(value,"list")
elif(value_type=="object"):
out+=readxlsx(value,"object")
if (topnum < sheet2.ncols - 1):
out += ","
out += "\n"
out += "}"
if (num < sheet2.nrows - 1):
if (xlsxname != "first"):
out += ","
out += "\n"
if (type == "list"):
out += "]"
return out
if __name__=='__main__':
p= readxlsx("first","object")
fp=open("smartJson.json","w", encoding='utf-8')
fp.write(p)
qq_14840239
- 粉丝: 6
- 资源: 4
最新资源
- Windows 串口通信工具putty
- 常用基础元件的PCB封装库SchLib/IntLib通用原理图库LED发光二极管
- java+mysql实现mvc.zip
- C#在线考试系统源码数据库 Access源码类型 WebForm
- 常用基础元件的PCB封装库SchLib/IntLib通用原理图库FLASH存储器
- Screenshot_20241117_061647_com.tencent.tmgp.sgame.jpg
- NI-VISA资源安装包
- 常用基础元件的PCB封装库SchLib/IntLib集成库常见基础元器件
- c++控制台RPG小游戏
- C#BS酒店管理系统源码数据库 SQL2008源码类型 WebForm
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈