import openpyxl as xl
from openpyxl import load_workbook
import pandas as pd
# opening the source excel file
filename1 ="elementsheetsample.xlsx"
wb1 = xl.load_workbook(filename1)
ws1 = wb1['Sheet1']
# opening the destination excel file
filename2 ="filledelementsheetsample.xlsx"
wb2 = xl.load_workbook(filename2)
ws2 = wb2['INACTIVE Sheet']
i1=9 #I row in file1
i2=4 #D row in file2
# calculate total number of rows and
# columns in source excel file
mr = ws1.max_row
mc = ws1.max_column
# copying the cell values from source
if i1==2:
if i2==2:
for j1 in range (2, mc +1):
for j2 in range (2, mc + 1):
c = ws1.cell(row = i1, column = j1)
ws2.cell(row = i2, column = j2).value = c.value
updatedtx = "updatedtx2.xlsx"
# saving the destination excel file
wb2.save(str(updatedtx))
我尝试了以下代码:
相关问题 更多 >
编程相关推荐