Method
sht.Range(‘G8’).Value=app.api.WorksheetFunction.Average(sht.Range(‘A1:A5’))
Sample Code
# Use the `WorksheetFunction` property
import xlwings as xw #Import the xlwings package
import os #Import the os package
root = os.getcwd() #Get the current path
#Create an Excel application window, visible,
#without opening a workbook
app=xw.App(visible=True, add_book=False)
#Open a data file, writable
bk=app.books.open(fullname=root+r'\Formula.xlsx',read_only=False)
sht=bk.api.Sheets(1) #Get the worksheet
#Use the `WorksheetFunction` property
sht.Range('G8').Value=app.api.WorksheetFunction.Average(sht.Range('A1:A5'))
bk.save('test.xlsx')
#bk.close()
#app.kill()

Leave a Reply