Ich habe versucht, mir das Tutorial anzusehen und auch etwas zu recherchieren, aber ich konnte anscheinend nicht verstehen, was ich falsch gemacht habe. Unten ist der Code, den ich verwende
Code: Select all
import openpyxl as opxl
#Opening the destination excel file
sourceFile = "C:\\ForTesting\\sourceFile.xlsx"
sourceworkbook = opxl.load_workbook(sourceFile)
sourceworksheet = sourceworkbook.worksheets[0]
#Opening the destination excel file
destinationFile = "C:\\ForTesting\\destinationFile.xlsx"
desinationworkbook = opxl.load_workbook(destinationFile)
destinationworksheet = desinationworkbook.active
# calculate total number of rows and
# columns in source excel file
maximum_row = sourceworksheet.max_row
maximum_column = sourceworksheet.max_column
# copying the cell values from source
# excel file to destination excel file
for i in range (1, maximum_row + 1):
for j in range (1, maximum_column + 1):
#reading the cell value from source excel file
c = sourceworksheet.cell(row = i, column = j)
#writing the value read from the source file to destination file
destinationworksheet.cell(row = i, column = j).value = c.value
#Save the destination excel file
sourceworkbook.save(str(destinationFile))
print("The File has been saved successfully")
Mobile version