Giorgos Synetos
Giorgos Synetos

Reputation: 467

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

in the active worksheet?

Apparently, the following doesn't work

wb = load_workbook(test.xlsx)
ws = wb['Sheet1']

ws['A1'] = "='Sheet2'!A1)" 

Upvotes: 0

Views: 1764

Answers (1)

Vignesh
Vignesh

Reputation: 1623

Did you save the workbook using 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')

Upvotes: 1

Related Questions