def read_excel():
# 打开文件
data = []
workbook = xlrd.open_workbook(r"C:UsersAdministratorDesktopwork_doccheck.xlsx", "r")
# 获取所有sheet
print(workbook.sheet_names() ) # [u'sheet1', u'sheet2']
sheet2_name = workbook.sheet_names()[0]
# 根据sheet索引或者名称获取sheet内容
sheet2 = workbook.sheet_by_index(0) # sheet索引从0开始
# sheet2 = workbook.sheet_by_name('sheet2')
# sheet的名称,行数,列数
rows = sheet2.get_rows()
n = 0
for i in rows:
data.append({
"gid": i[0].value,
"total":i[3].value,
"bill":i[4].value
})
# print(data[1:])
# print(type(data[1]["total"]))
# 获取整行和整列的值(数组)
# rows = sheet2.row_values(3) # 获取第四行内容
# cols_total = sheet2.col_values(3) # 获取第4列内容
# cols_bill = sheet2.col_values(4) # 获取第4列内容
# for i in
# print(cols_total)
# # 获取单元格内容
# print
# sheet2.cell(1, 0).value.encode('utf-8')
# print
# sheet2.cell_value(1, 0).encode('utf-8')
# print
# sheet2.row(1)[0].value.encode('utf-8')
# 获取单元格内容的数据类型
# print(sheet2.cell(1, 0).ctype)
data = {i["gid"]:i for i in data}
print(data)
return data