[python]Python to read directorys and write sheet (excel)

2021-5-20 写技术

import os
import xlwt

def file_name(file_dir):
    for root, dirs, files in os.walk(file_dir):
        list_files(files)


def list_files(files):
    workbook = xlwt.Workbook(encoding = 'utf-8')
    worksheet = workbook.add_sheet('Nicholas')
    lines = 1
    for item in files:
        print(item)
        items = item.split("_")
        print(items)
        cols = 1
        for col in items:
            if cols==1:
                col = col[8:10] + ':' + col[10:12] + ':' + col[12:14] + '.' + col[14:]
            worksheet.write(lines,cols,label=col)
            cols += 1

        lines += 1

    workbook.save('nicholas.xls')

file_name("./dirty")

标签: python

发表评论:

Powered by anycle 湘ICP备15001973号-1