Windows establece tareas programadas y ejecuta scripts de python (programa de tareas de Windows)

1. Escenario:
algunos archivos de python deben ejecutarse regularmente todos los días
2. Operación

2.1 Prepare el archivo py con anticipación

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 Uso de la programación de tareas de Windows

inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí

2.3 Efecto : el escritorio genera un archivo de Excel
inserte la descripción de la imagen aquí

Supongo que te gusta

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