# _*_ Coding:utf-8
Import Xlrd,sys
Import Pickle
Import JSON
Data=xlrd.open_workbook ("D:/test/6.xlsx")
# #读取工作表, methods can be indexed sequentially, or you can use Sheet_by_name (U "Sheet1")
Table = Data.sheet_by_index (0)
# # #读取内容摘要表并存入nrarr
nrarr={}
Table1 = Data.sheet_by_index (1)
For RO in range (2,table1.nrows):
jj= table1.row (RO) [0].value
#print ro
If JJ! = "":
Nr=table1.row (RO) [1].value
Nrarr[jj]=nr
#print nrarr[jj].encode (' gbk ', ' ignore ')
‘‘‘
#for k,v in Nrarr.items ():
# print K, V.encode (' GBK ', ' ignore ')
#print k.encode (' GBK '), V.encode (' GBK ')
# #获取工作表数量
#tables = Data.nsheets
# #获取整行, the value of the whole column (return array)
#table. Row_values (N)
#table. Col_values (N)
# #单元格操作
#cell_A1 = Table.cell (0,0). Value
#cell_C4 = Table.cell (2,3). Value
# #行列索引
#table. Row (0) [1].value
#table. Col (1) [0].value
‘‘‘
# #获取总行数
nrows = Table.nrows
# #获取列数
Ncols = Table.ncols
List=[]
For RN in range (3, nrows):
allarr={}
JN = Table.row (RN) [0].value
allarr[' xxx '] = Jn
allarr["xx"] = Table.row (RN) [10].value
allarr[' xx '] =str (Table.row (RN) [16].value]
#allarr [' xx '] = Table.row (RN) [5].value
allarr[' xx '] = ""
allarr[' xx '] = Table.row (RN) [7].value
allarr[' xx '] = Table.row (RN) [8].value
allarr[' xx '] = U ' Chinese '
allarr[' xx '] = Table.row (RN) [4].value
allarr[' xx ']=nrarr[jn]
List.append (Allarr)
# #生成json并写入文件
JS = json.dumps (list)
Output = open ("D:/test/oo.json", ' W ')
Output.write (JS)
Output.close ()
# # #读json
Jf=json.load (Open ("D:/test/oo.json"))
For LS in JF:
For k,v in Ls.items ():
Print K,v.encode (' gbk ', ' ignore ')
#print k,v
This article is from the Linux OPS blog, so be sure to keep this source http://11247321.blog.51cto.com/3481782/1547362
Python read Excel generates JSON read JSON