Python read Excel generates JSON read JSON

Source: Internet
Author: User

# _*_ 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 "keep up with The Times" blog, please be sure to retain this source http://2643235.blog.51cto.com/2633235/1547367

Python read Excel generates JSON read JSON

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.