zoukankan      html  css  js  c++  java
  • 《xls json csv 文件读取》

    #coding=utf-8
    import xlrd
    import json
    import csv
    
    #地址前用'\'转译符要加
    workbook=xlrd.open_workbook('D:/untitled/1022/date.xls')
    #提取表格名称
    sheets=workbook.sheet_names()
    #提取第一个表格内容
    worksheet=workbook.sheet_by_name((sheets[0]))
    
    #统计有多少行
    worksheet.nrows
    #统计有多少列
    worksheet.ncols
    #遍历所以单元格
    for i in range(worksheet.nrows):
        for j in range(worksheet.ncols):
            print(worksheet.cell_value(i,j),'\t',end='')
        print('')
    
    #json load(filed)出来直接是对象
    with open('D:/untitled/1022/date.json','r',encoding='utf-8') as filed:
        filedd = json.load(filed)
        print(filedd)
    
    #csv.DictReader(fils)出来是首行对应值字典
    with open('D:/untitled/1022/date.csv','r',encoding='utf-8') as fils:
        global jsonlist
        jsonlist = []
        reader=csv.DictReader(fils)
        for i in reader:
            print(i)
            #转换成字典
            print(dict(i))
            jsonlist.append(dict(i))
    
    with open('D:/untitled/1022/date.csv','r',encoding='utf-8') as fils:
        #不能提取第一行
        reader=csv.reader(fils)
        for i in reader:
            print(i)
  • 相关阅读:
    CSS动画小结
    CSS效果常见问题
    CSS效果小结
    CSS(非布局样式)
    CSS(选择器)
    SkipList
    实现一个简易版RPC
    实现一个简易版的SpringMvc框架
    关于缓存击穿
    java多线程系列 目录
  • 原文地址:https://www.cnblogs.com/huazhou695/p/9885810.html
Copyright © 2011-2022 走看看