当前位置:网站首页>Using openpyxl module to write the binary list into excel file

Using openpyxl module to write the binary list into excel file

2022-07-05 01:15:00 xutengfei999

import openpyxl
import os
if sys.platform == "win32":
    EMAIL_PATH = "F:/email"
else:
    EMAIL_PATH = "/usr/local/workspace-ztcm/email"
# Write the two-dimensional list of stored error information to the specified path 
def writeToExcel(file_path, new_list):
    email_dir_path = os.path.join(file_path, timestamp)
    if not os.path.exists(email_dir_path):
        os.makedirs(email_dir_path)
    emailfile_path = os.path.join(email_dir_path,' Zhengtong media data crawling exception notice .xlsx')
    wb = openpyxl.Workbook()
    ws = wb.active
    ws.title = ' Abnormal information of Zhengtong media '  #sheet name 
    for r in range(len(new_list)):
        for c in range(len(new_list[0])):
            ws.cell(r + 1, c + 1).value = new_list[r][c]
            # excel The rows and columns in are from 1 Start counting , So we need to +1
    wb.save(emailfile_path)  #  Save after writing 
    print(" Successfully written file : " + emailfile_path + " !")
    return 1

if __name__ == "__main__":

        

error_log_list= [['ccgp_shaanxi_feibiao', ' China government procurement network ', '200: 86 302: 1 403: 1', 'F:/spider_log\\\\ccgp_shaanxi_feibiao\\\\20220208112516\\\\scrapy_ccgp_shaanxi_feibiao_2022_2_8.log', '2022-02-08 11:28:05 '], ['ccgp_shaanxi_zhongbiao', ' China government procurement network ', '200: 4074 302: 11 403: 11', 'F:/spider_log\\\\ccgp_shaanxi_zhongbiao\\\\20220208131055\\\\scrapy_ccgp_shaanxi_zhongbiao_2022_2_8.log', '2022-02-08 15:13:51 ']]

writeToExcel(EAMIL_PATH,error_log_list)

原网站

版权声明
本文为[xutengfei999]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141039282244.html

随机推荐