zoukankan      html  css  js  c++  java
  • xls文件转化txt

    xls文件转化txt

    # -*- coding:utf-8 -*-
    # 安装pywin32包 http://sourceforge.net/projects/pywin32/files/pywin32/
    # windows 7下使用通过
    #
    
    import os, sys 
    from fnmatch import fnmatch
    import win32com.client
    
    if len(sys.argv)<=2:
        print "python %s inputdir  outputdir" % os.path.basename(sys.argv[1])
        sys.exit(1)
    
    input = sys.argv[1]
    output = sys.argv[2]
    
    if not os.path.exists(output): os.mkdir(output)
    
    i = 1
    wordapp = win32com.client.gencache.EnsureDispatch("Excel.Application")
    wordapp.Visible = 0
    wordapp.DisplayAlerts = 0
    
    for path, dirs, files in os.walk(input):
        docs = [os.path.abspath(os.path.join(path, f)) for f in files if fnmatch(f, '*.xls')]
        for doc in docs:
            doc2txt = os.path.join(output, os.path.basename(doc.rstrip('xls') + 'txt'))
            doc2txt = os.path.abspath(doc2txt)
            if os.path.exists(doc2txt): continue
            print " processing [%d] %s " % (i, doc)
            i +=1    
            wddoc = wordapp.Workbooks.Open(doc)
            wddoc.SaveAs(doc2txt, FileFormat=6)
            wddoc.Close()
    wordapp.Quit()
    
    
    

    --- 她说, 她是仙,她不是神
  • 相关阅读:
    UE4 Abc 批量导入
    UE4源码摘录(424)
    JZ10 矩形覆盖
    JZ27 字符串的排列
    JZ66 机器人的运动范围
    JZ65 矩阵中的路径
    JZ12 数值的整数次方
    JZ37 数字在升序数组中出现的次数
    JZ6 旋转数组的最小数字
    JZ67 剪绳子
  • 原文地址:https://www.cnblogs.com/bregman/p/4690039.html
Copyright © 2011-2022 走看看