O Windows define tarefas agendadas e executa scripts python (agendamento de tarefas do Windows)

1. Cenário:
Alguns arquivos python precisam ser executados regularmente todos os dias
2. Operação

2.1 Prepare o arquivo py com antecedência

import xlsxwriter
import os

#更改路径
os.chdir(r"C:\Users\XXUZ\Desktop")
new_excel = '测试文件.xlsx'
if os.path.exists(new_excel) :
        os.remove(new_excel)
workbook = xlsxwriter.Workbook(new_excel)
worksheet = workbook.add_worksheet('这是sheet1')
title_format = {
    
    
    'font_name' : '微软雅黑', # 字体
    'font_size': 12,  # 字体大小
    'font_color': 'black',  # 字体颜色
    'bold': True,  # 是否粗体
    'bg_color': '#101010',  # 表格背景颜色
    'fg_color': '#00FF00',  # 前景颜色
    'align': 'center',  # 水平居中对齐
    'valign': 'vcenter',  # 垂直居中对齐
    # 'num_format': 'yyyy-mm-dd H:M:S',# 设置日期格式
    # 后面参数是线条宽度
    'border': 1,  # 边框宽度
    'top': 1,  # 上边框
    'left': 1,  # 左边框
    'right': 1,  # 右边框
    'bottom': 1  # 底边框
}
format = {
    
    
    'font_size': 10,  # 字体大小
    'font_color': 'blue',  # 字体颜色
    'bold': False,  # 是否粗体
    'bg_color': '#101010',  # 表格背景颜色
    'fg_color': '#00FF00', # 前景颜色
    'align': 'center',  # 水平居中对齐
    'valign': 'vcenter',  # 垂直居中对齐
    # 'num_format': 'yyyy-mm-dd H:M:S',# 设置日期格式
    # 后面参数是线条宽度
    'border': 1,  # 边框宽度
    'top': 1,  # 上边框
    'left': 1,  # 左边框
    'right': 1,  # 右边框
    'bottom': 1  # 底边框
}
title_style = workbook.add_format(title_format)  # 设置样式format是一个字典
style = workbook.add_format(format)  # 设置样式format是一个字典
worksheet.write_row(0, 0, ['表头1','表头2'], title_style)  # 第一行第一列开始写入表头
worksheet.write_row(1, 0, ['数据1','数据2'], style)  # 第二行第一列开始写入数据
workbook.close()

2.2 Usando o agendamento de tarefas do Windows

insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui
insira a descrição da imagem aqui

2.3 Efeito : A área de trabalho gera um arquivo excel
insira a descrição da imagem aqui

Acho que você gosta

Origin blog.csdn.net/shammy_feng/article/details/124178086
Recomendado
Clasificación