openpyxl
使用python修改excel文档,保留文档原有的样式风格
代码语言:javascript复制import numpy as np
import openpyxl as pd
from datetime import datetime, time
from random import *
one = True
def read(sheet):
global one
for row in sheet:
for cell in row:
if isinstance(cell.value,time):
cell.value = time(8,randint(28,40)) if one else time(17,randint(30,59))
one = not one
table = pd.load_workbook('2022.4.xlsx')
sheet=table['2022.4']
read(sheet)
table.save('2022.4__1.xlsx')