【发布时间】:2021-11-09 01:28:09
【问题描述】:
我编写了一个程序,它从一张纸上获取数据并将其粘贴到另一张纸上。但是,当我尝试保存工作簿时,它给了我一个错误。文件名名称应与在前一行中输入的名称相同,但我不确定如何使保存功能适用于工作簿。我试过使用变量 input 和它的 str 但都没有成功。
unit_list = input("Please enter the file name: ")
unit_list = load_workbook(unit_list)
all_units = unit_list["Sheet1"]
picked_units = unit_list["Sheet2"]
row_count = all_units.max_row
col_count = all_units.max_column
need_units = int(input("How many units need to be checked? "))
nul = []
while len(nul)+1 <= need_units:
unit = rand_seed(row_count)
if unit not in nul:
nul.append(unit)
for j in range(1, col_count+1):
c = all_units.cell(row=unit+1, column=j)
picked_units.cell(row=len(nul), column=j).value = c.value
unit_list.save(filename=unit_list)
【问题讨论】: