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"
               

  • 相关阅读:
    C# Yield的使用
    vs code使用Markdown编辑使用插件
    理解IEnumerable和IQueryable
    LINQ使用CopyToDataTable
    Predicate委托
    Func委托
    Action委托
    Delegate委托
    TypeError: Cannot read property 'thisCompilation' of undefined
    由于找不到vcruntime140.dll,无法继续执行代码。
  • 原文地址:https://www.cnblogs.com/wj2ge/p/6412826.html
Copyright © 2011-2022 走看看