[英]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. 我正在使用模块
xlwd
, xlwt
和xlutil
在Python中进行一些Excel操作。 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. 我无法弄清楚如何在Python的Excel文件的同一张表中将单元格
(X,Y)
的值复制到单元格(A,B)
。 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. 在数以万计的2个单元中工作……非常微薄。 Normally,one should present an iteration over rows x columns.
通常,应该在行x列上进行迭代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.