zoukankan      html  css  js  c++  java
  • 统计excel表格的py

    # -*- coding: utf-8 -*-

    import xlrd
    import xlwt
    import os
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')
    xlrd.Book.encoding = "gbk"

    type=sys.getfilesystemencoding()
    s = os.sep
    counter = 0
    chipan = "e:"
    wenjianjia = "hh"
    wenjianjia = wenjianjia.decode('utf-8').encode(type)
    root = chipan + s + wenjianjia + s
    for root,dirs,files in os.walk(root):
        for dir in dirs:
            os.path.join(root,dir).decode('gbk').encode('utf-8')
        for file in files:
            filename = os.path.join(root,file).decode('gbk').encode('utf-8')
            if (os.path.splitext(filename)[1] == '.xls')or(os.path.splitext(filename)[1] == '.xlsx'):
                try:
                    print filename.decode('utf-8').encode(type)
                    uipath = unicode(filename, "utf8")
                    data = xlrd.open_workbook(uipath)
                    table = data.sheets()[0]
                    assert isinstance(table.nrows, object)
                    nrows = table.nrows
                    counter += nrows
                    print counter
                except:
                    print "error"
               

  • 相关阅读:
    mysql 常用sql操作总结
    c# 安装windows服务
    c# Ajax后台动态分页
    c# SQLHelper总汇
    C#调用Web Service时的身份验证
    c#定时调用作业
    【转】Powerdesigner逆向工程从sql server数据库生成pdm
    aspx页面@Page指令解析
    C# 简单日志文本输出
    【摘抄】C# DateTime.Now详解
  • 原文地址:https://www.cnblogs.com/wj2ge/p/6412826.html
Copyright © 2011-2022 走看看