哪个大神帮我改下代码,从数据中提取出来写入到excel表

#!usr/bin/python
#coding=utf-8

import os
import os.path
import fnmatch
import xlwt
import line***

#遍历文件夹输出所有的子文件名
def GetFileList(dir, fileList):
    newDir = dir
    if os.path.isfile(dir):
        fileList.append(dir.decode('gbk'))
    elif os.path.isdir(dir):
        for s in os.listdir(dir):
            newDir = os.path.join(dir, s)
            GetFileList(newDir, fileList)
    return fileList


list = GetFileList('E:\\kfile_hardware&pw',[])
list_name=[]
for i in list:
    list_name.append(i)
#print list_name

#读取所有文件中的内容
content_name=[]    

for filename in list_name:
    fileHandle = open (filename)
    #在info文件里前4行是不需要的,因此从第五读起
    
    if fnmatch.fnmatch(filename,"*.info"):
    
        fileList = fileHandle.readlines()[4:]
        for fileLine in fileList:
            content_name.append(fileLine)
    else:
        fileList = fileHandle.readlines()
        for fileLine in fileList:
            content_name.append(fileLine)
    #print content_name
    fileHandle.close()


    
    
    

#插入excel表
#建立工作薄、建立工作表
wb = xlwt.Workbook()
ws = wb.add_sheet('sheet',cell_overwrite_ok=True)
#输入0行
rows= [u'服务器SN',u'root密码',u'cpu',u'CPU内存1',u'内存2',u'数据盘1',u'数据盘2',u'数据盘3',u'数据盘4',u'数据盘5',u'数据盘6',u'mac地址']
for i in range(0,len(rows)):
    ws.write(0,i,rows[i])

    row=0
    col=0
for str in content_name:
    if row//len(rows)==0:
        col+=1
        row=row-len(rows)
        ws.write(col,row,str)
    
    else:
        
        ws.write(col,row,str)
   
全部评论
试试用pandas处理数据
点赞 回复 分享
发布于 2016-09-08 14:49

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务