简体   繁体   中英

Copying value of cell (X,Y) to cell (A,B) in same sheet of an Excel file using Python

I am using the modules xlwd , xlwt and xlutil to do some Excel manipulations in Python. I am not able to figure out how to copy the value of cell (X,Y) to cell (A,B) in the same sheet of an Excel file in Python. Could someone let me know how to do that?

import xlrd
import xlwt
import xlutils
from xlutils.copy import copy 

r_book = xlrd.open_workbook(fname)
w_book = xlutils.copy.copy(r_book)
r_sheet = r_book.sheets()[0] # Taking the first sheet
w_sheet = w_book.get_sheet(0)

x_y_value = r_sheet.cell(X, Y).value
w_sheet.write(A, B, x_y_value)
w_book.save(fname)

Work on 2 cells among tens of thousands...quite meager. Normally,one should present an iteration over rows x columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM