[英]Openpyxl - How to reference cell on another sheet
Is there a way to reference a cell A1 from Sheet2 to cell A1 of Sheet1?有没有办法将 Sheet2 的单元格 A1 引用到 Sheet1 的单元格 A1?
='Sheet2'!A1 ='Sheet2'!A1
in the active worksheet?在活动工作表中?
Apparently, the following doesn't work显然,以下不起作用
wb = load_workbook(test.xlsx)
ws = wb['Sheet1']
ws['A1'] = "='Sheet2'!A1)"
Did you save the workbook using wb.save ?您是否使用wb.save保存了工作簿? and Also remove the ) in the formula.并删除公式中的) 。
use this code below for achieving the functionality.使用下面的代码来实现功能。
import openpyxl
wb=openpyxl.load_workbook('test.xlsx')
ws = wb['Sheet1']
ws['A1'] = "='Sheet2'!A1"
wb.save('test.xlsx')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.