1.
import openpyxl
# 读取源Excel表格
source_file_path = 'path_to_source_excel.xlsx'
wb_source = openpyxl.load_workbook(source_file_path)
source_sheet = wb_source.active
# 创建新的Excel表格
wb_new = openpyxl.Workbook()
new_sheet = wb_new.active
# 指定复制次数
repeat_times = 3
# 遍历源表格的每一行
for row in source_sheet.iter_rows(min_row=2, values_only=True): # 假设第一行是标题
employee_id, employee_name = row
for _ in range(repeat_times):
new_sheet.append([employee_id, employee_name])
# 保存新表格
new_file_path = 'path_to_new_excel.xlsx'
wb_new.save(new_file_path)
print("新表格已生成!")
2.
import openpyxl
# 读取源Excel表格
source_file_path = 'D:/123/123.xlsx'
wb_source = openpyxl.load_workbook(source_file_path)
source_sheet = wb_source.active