首页 > 代码库 > python编程快速上手之第12章实践项目参考答案(12.13.3)

python编程快速上手之第12章实践项目参考答案(12.13.3)

 1 #! python3
 2 import openpyxl,os,glob
 3 os.chdir(C:\\Users\\Administrator\\Python35-32)
 4 list=glob.glob(*.txt)
 5 print(list)
 6 wb = openpyxl.Workbook()
 7 sheet = wb.get_active_sheet()
 8 columnNum=0
 9 for fliename in list:
10   file_object = open(str(fliename),rb)
11   alllines=file_object.readlines()
12   lineNum=0
13   columnNum += 1
14   for line in alllines:
15     lineNum += 1
16     sheet.cell(row=lineNum, column=columnNum).value=http://www.mamicode.com/line
17 wb.save(TxttoExcel.xlsx)

 

python编程快速上手之第12章实践项目参考答案(12.13.3)