Python实操快速统计用户加班或早退时长

from openpyxl import Workbook, load_workbook
from datetime import date


def create_data():
    wb = Workbook()
    sh = wb.active
    rows = [['data', 'batcj', 'bt', 'bat3'], [date(2020, 12, 1), 40, '11:30', 24],
            [date(2020, 12, 2), '30', '12:12', 209],
            [date(2020, 12, 3), '140', '12:30', 26],
            [date(2020, 12, 4), '30', '12:40', 24],
            [date(2020, 12, 5), '740', '12:30', 54]]
    for r in rows:
        sh.append(r)
    wb.save('demo.xlsx')


def stati():
    path = 'E:Python/Poject1/demo.xlsx'
    wb = load_workbook(path)
    sh = wb.active
    data = []
    for r in range(2, sh.max_row+1):
        row_data = []
        for c in range(2, sh.max_column+1):
            row_data.append(sh.cell(r, c).value)
        print(row_data)
        h, m = row_data[1].split(':')
        full = int(h)*60+int(m)
        tmp = full-18*60
        row_data.append(tmp)
        data.append(row_data)
    n_wb = Workbook()
    n_sh = n_wb.active
    for r in data:
        n_sh.append(r)
    n_wb.save('demo.xlsx')


create_data()
stati()

你可能感兴趣的:(Python,python,前端,linux)