Home > other >  Using XLRD and xlutils wrote two excel function to execute when always quote Can 't load sheets
Using XLRD and xlutils wrote two excel function to execute when always quote Can 't load sheets

Time:12-04

When executing code excel_copy replication can succeed, generate a time-stamped excel File, but in the use of excel_write, execution to fw. Get_sheet (0), write (row, column, content) is an error, the File "D: \ Python \ Python38 \ lib \ site - packages \ XLRD \ book py", line 699, in get_sheet
Raise XLRDError (" Can 't load sheets after releasing resources.
")XLRD. Biffh. XLRDError: Can 't load sheets after releasing resources.

Function is as follows:
Def excel_write (dir, name, row, column, content,) :
# dir: test script path/, name: name of the file with the suffix, row: which line of writing, from the column: from which column write
OS. The chdir (dir)
Fw=XLRD. Open_workbook (name)
Fw. Get_sheet (0). Write (row, column, content)
Fw. Save (name)

Def excel_copy (dir, name, new_path) :
# new_path format:/test result/
OS. The chdir (globalValues GLOBAL_path1 + dir)
Fr=XLRD. Open_workbook (name, on_demand=False)
Fn=copy (fr)
# test scripts time-stamped as suffix save
Rename_list=list (name)
The index=name. The find (' xl ')
Rename_list. Insert (index, time. Strftime (" % % m % d % Y H % m % S "))
Rename="'. Join (rename_list)
New_path=globalValues. GLOBAL_path1 + new_path
Fn. Save (new_path + rename)
Return new_path, rename

Execute the following statement:
(new_path, rename)=excel_copy ('/Test case/', 'the Test script. XLS', '/Test result/')
Time. Sleep (1)
Excel_write (new_path, rename, 1, 4, 'test')

CodePudding user response:

Has been solved, def excel_write (dir, name, row, column, content,) increases the copy is not an error,
  • Related