• python 读excel


    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    import sys
    import pycontrol.pycontrol as pc
    import time
    import csv
    import ssl
    from datetime import date,datetime
    
    import xlrd
    
    def read_excel(a):
      wb=xlrd.open_workbook(filename=a) #打开文件
      print wb.sheet_names() ##获取所有sheet页名字
      print type(wb.sheet_names())
      for x in wb.sheet_names():
           print type(x)
           print  x.encode('utf-8')
      sheet1=wb.sheet_by_name(u'批量提交')
      print sheet1.name,sheet1.ncols,sheet1.nrows
      b=sheet1.nrows
      list = [[] for i in range(b)]
      for i in range(sheet1.nrows):
           if i==0:
               pass
           else:
               print sheet1.row(i)
               print type(sheet1.row(i))
               for j in  xrange(len(sheet1.row(i))):
                   #print j
                   if j==7:
                    #print j
                    # print  sheet1.row(i)[j].value
                    # print  sheet1.row(i)[j].value
                    print xlrd.xldate_as_datetime(sheet1.row(i)[j].value,0)
                    list[i].append(xlrd.xldate_as_datetime(sheet1.row(i)[j].value,0))
                    #print  sheet1.row(i)[j].value.ctype
                    #print date(sheet1.row(i)[j].value).strftime("%Y-%m-%d %H:%M:%S")
                   else:
                    print  sheet1.row(i)[j].value
                    list[i].append(sheet1.row(i)[j].value)
      return list
    lista=read_excel('test.xlsx')
    while [] in lista:
        lista.remove([])
    print lista
    
  • 相关阅读:
    致亲爱的304
    C语言中简单的for循环和浮点型变量
    C程序内存管理
    变量
    我哭了
    那一场邂逅
    如何修改安卓项目的图标
    Android requires compiler compliance level 5.0 or 6.0. Found '1.4' instead.解决方法
    Android 异步加载
    大家好,第一次用博客记录一些东西
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348789.html
Copyright © 2020-2023  润新知