美文网首页
python读文件,存excel

python读文件,存excel

作者: 金琥 | 来源:发表于2019-01-10 19:29 被阅读5次

用python逐行读取文件,取需要的字段保存到excel中

import openpyxl
def main():
    workbook = openpyxl.load_workbook("new.xlsx")
        sheet = workbook['Sheet1']
        with open("Url.txt", 'r', encoding='utf8') as file:
            readline = file.readline()
            while readline:
                if readline.find('\"') >= 0:
                    resultstr = readline.split('\"')[1]
                    row = [resultstr, ]
                    sheet.append(row)
                readline = file.readline()
        workbook.save("new.xlsx")
        workbook.close()

相关文章

网友评论

      本文标题:python读文件,存excel

      本文链接:https://www.haomeiwen.com/subject/jkczrqtx.html