哪个大神帮我改下代码,从数据中提取出来写入到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)
#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)