【办公类-53-01】2024年第一学期校历制作(星火讯飞提取实际工作日,5天一行)

8328d475accd4f9d83224ea607153b52.png

背景需求:

【办公类-16-06】“校历(月日版)”(python 排班表系列)_python 每日值班-CSDN博客文章浏览阅读1k次。【办公类-16-06】“校历(月日版)”(python 排班表系列)_python 每日值班https://blog.csdn.net/reasonsummer/article/details/127234880

今天去单位,从网上下载校历

9fdb7a93c06e4427ae03c68b6c393a68.png

用PPT制作分月校历

f1b4e9a55f194c7c93431068f9b615b4.pngb4a9c68250e04fc0b4f4e8bc61bd4db8.png

我想进一步用代码提取每周第一个工作日和最后一个工作日的日期

设计工具:

用星火讯飞写出自己的需求

5f2e3488eaad48fb9f11b7a1a699ca83.png

7e84834c9e4c4e068abe079618a64294.png96d825e60a1d4e0b922d40394e1c4b0c.png

c89e00506015479ba0a5e6cdc125c66b.png

86e7cbe608d24297bb82af3cb8491108.png

b104ba3247bf4bd09f46089c943ff08f.png

代码展示

'''
2024学年第一学期校历
星火讯飞 阿夏
2024年7月29日
'''


# -*- coding: utf-8 -*-

import datetime
import openpyxl
from openpyxl.styles import Alignment, PatternFill
import time


# 创建一个新的Excel工作簿
workbook = openpyxl.Workbook()
sheet = workbook.active

# 设置标题行
title_row = ["周次", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
sheet.append(title_row)

# 设置日期范围
start_date = datetime.date(2024, 9, 2)
end_date = datetime.date(2025, 1, 17)

# 计算周数和日期
current_week = 1
current_day = start_date
while current_day <= end_date:
    # 获取当前周的第一天(星期一)
    week_start = current_day - datetime.timedelta(days=current_day.weekday())
    
    # 如果当前日期是新的一周,添加新行并更新周数
    if current_day == week_start:
        sheet.append([f"第{current_week}周"])
        current_week += 1
    
    # 在正确的单元格中添加日期
    column_index = current_day.weekday() + 2  # 从B列开始,所以加2
    cell = sheet.cell(row=current_week, column=column_index)
    cell.value = current_day.strftime("%Y-%m-%d")
    # cell.value = current_day.strftime("%m/%d")
    # cell_value = current_day.strftime("%Y年%m月%d日").encode('utf-8')
    cell.alignment = Alignment(horizontal='center', vertical='center')
    
     # 如果日期不等于周六和周日,就把这个单元格填充为浅黄色
    if current_day.weekday() not in (5, 6):
        light_yellow_fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")
        cell.fill = light_yellow_fill

    
    
    # 如果日期等于2024-09-14、2024-10-12、9月16日、9月17日、10月1日到10月8日、2025年1月1日,单元格填充为白色
    special_dates = [datetime.date(2024, 9, 14), datetime.date(2024, 10, 12), datetime.date(2024, 9, 16), datetime.date(2024, 9, 17)]
    for i in range(1, 8):
        special_dates.append(datetime.date(2024, 10, i))
    special_dates.append(datetime.date(2025, 1, 1))
    if current_day in special_dates:
        white_fill = PatternFill(start_color="FFFFFF", end_color="FFFFFF", fill_type="solid")
        cell.fill = white_fill

    # 如果日期等于2024-09-14或2024-10-12,单元格填充为黄色
    if current_day == datetime.date(2024, 9, 14) or current_day == datetime.date(2024, 9, 29) or current_day == datetime.date(2024, 10, 12):
        yellow_fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")
        cell.fill = yellow_fill
    
    # 移动到下一天
    current_day += datetime.timedelta(days=1)

   

path=r'C:\Users\jg2yXRZ\OneDrive\桌面\校历'
# 保存工作簿
workbook.save(path+r"\2024学年第一学期校历.xlsx")
time.sleep(2)



import openpyxl
from openpyxl.styles import PatternFill

# 打开已存在的Excel文件
workbook = openpyxl.load_workbook(path+r"\2024学年第一学期校历.xlsx")
sheet = workbook.active

# 设置黄色填充样式
yellow_fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")

# 提取单独的第一个黄、最后一个黄
# # 遍历每一行
# for row in range(2, sheet.max_row + 1):
#     # 读取每一行第一个黄色填充单元格的数字,写入I列
#     for col in range(2, sheet.max_column + 1):
#         cell = sheet.cell(row=row, column=col)
#         if cell.fill == yellow_fill:
#             sheet.cell(row=row, column=9).value = cell.value
#             break
#     # 读取每一行最后一个黄色填充单元格的数字,写入J列
#     for col in range(sheet.max_column, 1, -1):
#         cell = sheet.cell(row=row, column=col)
#         if cell.fill == yellow_fill:
#             sheet.cell(row=row, column=10).value = cell.value
#             break

# 合并在一起的第一个日期和最后一个日期
for row in range(2, sheet.max_row + 1):
    # 读取每一行第一个黄色填充单元格的数字
    first_cell_value = None
    for col in range(2, sheet.max_column + 1):
        cell = sheet.cell(row=row, column=col)
        if cell.fill == yellow_fill:
            first_cell_value = cell.value
            break
    
    # 读取每一行最后一个黄色填充单元格的数字
    last_cell_value = None
    for col in range(sheet.max_column, 1, -1):
        cell = sheet.cell(row=row, column=col)
        if cell.fill == yellow_fill:
            last_cell_value = cell.value
            break
    
    # 组合数字并写入K列
    if first_cell_value is not None and last_cell_value is not None:
        combined_value = f"{first_cell_value}——{last_cell_value}"
        sheet.cell(row=row, column=9).value = combined_value



workbook.save(path+r"\2024学年第一学期校历.xlsx")

032f568c930a4236b51d0123823782f8.png

白色的填充日期说明是双休日或国定假日

黄色的填充日期需要上班的。

8d847d4f7e954f1cbb947ef0f5baf827.png

有国定假日的几周实际上班天数有多有少,如果想要统一凑满5天一周,就要手动调整

8d3b3d440e7440c5888c1798e5ad25bf.png

以下是手动调整的日期(凑满5天)

fe26a39f1aba48f2bb75797fd0aa7ca1.png

我这里希望日期是年月日样式

86c982941b5a451b9a636beff15b0675.png

但是改成年月日,总是报错

2c3a0266498348d8bd496598a96157ab.png627e887d5e0f4467925291825cd9f7d9.png

目前还是用“符号”日期,可以生成。

90e22c48aa8247438db410e86d0e8ff4.png

51ccf69789a54916abc33760864ce007.png

7145a0d8c74944a985964e1cfdb56d72.png

后续研究:

1、年月日版

2、生成对对应五天的“星期“

3、生成对对应五天(包含节日名称)

  • 19
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,校历是一个常见的日历应用,我们可以使用uni-app的组件和API来实现。 首先,我们需要创建一个uni-app的项目,并在pages文件夹下创建一个校历的页面,比如命名为calendar.vue。 接下来,我们需要引入uni-app的日历组件uni-calendar,可以在页面的template中添加以下代码: ```html <template> <view> <uni-calendar :options="options"></uni-calendar> </view> </template> ``` 其中,options是需要传递给日历组件的参数,我们可以在data中定义一个options对象。比如: ```javascript export default { data() { return { options: { title: '2022校历', // 标题 headerBgColor: '#007AFF', // 头部背景颜色 headerColor: '#fff', // 头部文字颜色 theme: 'default', // 主题样式,可选:'default'、'simple'、'grid'、'card' firstDayOfWeek: 1, // 每周的第一,0为周日,1为周一 showLunar: true, // 是否显示农历 showFestival: true, // 是否显示节日 showHoliday: true, // 是否显示假期 showTerm: true, // 是否显示学期 showMark: true, // 是否显示标记 showHolidayPrice: true, // 是否显示假期价格 showTermPrice: true, // 是否显示学期价格 holiday: [], // 假期数据 term: [], // 学期数据 mark: [], // 标记数据 holidayPrice: {}, // 假期价格数据 termPrice: {}, // 学期价格数据 }, }; }, }; ``` 接着,我们需要在页面的script中添加uni-calendar组件的引用: ```javascript import UniCalendar from '@/components/uni-calendar/uni-calendar.vue'; export default { components: { UniCalendar, }, data() { // ... }, }; ``` 最后,我们可以在页面的created生命周期中初始化options对象,并设置假期、学期、标记和价格等相关数据。比如: ```javascript export default { components: { UniCalendar, }, data() { return { options: {}, }; }, created() { const year = 2022; // 当前份 const holiday = [ // 假期数据 { name: '元旦节', start: `${year}-01-01`, end: `${year}-01-03`, }, { name: '春节', start: `${year}-02-01`, end: `${year}-02-07`, }, { name: '清明节', start: `${year}-04-03`, end: `${year}-04-05`, }, { name: '劳动节', start: `${year}-05-01`, end: `${year}-05-03`, }, { name: '端午节', start: `${year}-06-02`, end: `${year}-06-04`, }, { name: '中秋节', start: `${year}-09-10`, end: `${year}-09-12`, }, { name: '国庆节', start: `${year}-10-01`, end: `${year}-10-07`, }, ]; const term = [ // 学期数据 { name: '第一学期', start: `${year}-02-21`, end: `${year}-07-01`, }, { name: '第二学期', start: `${year}-09-01`, end: `${year}-12-31`, }, ]; const mark = [ // 标记数据 { date: `${year}-02-01`, text: '开学', }, { date: `${year}-07-02`, text: '放假', }, { date: `${year}-08-20`, text: '开学', }, { date: `${year}-12-31`, text: '放假', }, ]; const holidayPrice = { // 假期价格数据 [`${year}-01-01`]: 200, [`${year}-01-02`]: 200, [`${year}-01-03`]: 200, [`${year}-02-01`]: 300, [`${year}-02-02`]: 300, [`${year}-02-03`]: 300, [`${year}-02-04`]: 300, [`${year}-02-05`]: 300, [`${year}-02-06`]: 300, [`${year}-02-07`]: 300, [`${year}-04-03`]: 150, [`${year}-04-04`]: 150, [`${year}-04-05`]: 150, [`${year}-05-01`]: 200, [`${year}-05-02`]: 200, [`${year}-05-03`]: 200, [`${year}-06-02`]: 150, [`${year}-06-03`]: 150, [`${year}-06-04`]: 150, [`${year}-09-10`]: 150, [`${year}-09-11`]: 150, [`${year}-09-12`]: 150, [`${year}-10-01`]: 350, [`${year}-10-02`]: 350, [`${year}-10-03`]: 350, [`${year}-10-04`]: 350, [`${year}-10-05`]: 350, [`${year}-10-06`]: 350, [`${year}-10-07`]: 350, }; const termPrice = { // 学期价格数据 [`${year}-02-21`]: 3000, [`${year}-07-01`]: 4000, [`${year}-09-01`]: 3500, [`${year}-12-31`]: 4000, }; this.options = { title: `${year}校历`, holiday, term, mark, holidayPrice, termPrice, }; }, }; ``` 这样,一个简单的校历应用就完成了!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿夏reasonsummer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值