Python Bytes - Openpyxl Add Excel Formula Last Row of Data Across All Columns Code in Description

Published: 22 July 2023
on channel: AC
837
9

#Coded by Andrew C

from subprocess import call, sys

def install(package):
call([
sys.executable,
"-m",
"pip",
"--disable-pip-version-check",
"-q",
"install",
package
])

install('openpyxl')

from openpyxl import load_workbook
import pandas as pd
from openpyxl.utils import get_column_letter

workbook = load_workbook(filename="/Users/Downloads/wine.xlsx")
workbook.sheetnames

sheet = workbook["beans"]

df = pd.read_excel("/Users/elizabeth/Downloads/wine.xlsx", sheet_name= "beans")

y = df.shape[1]

for x in range(1,int(y)+1):
sheet[get_column_letter(x)+str(df.shape[0]+2)] = "=sum("+ get_column_letter(x) + "2:" + get_column_letter(x) + str(df.shape[0]+1)+")"

workbook.save(filename="/Users/elizabeth/Downloads/wine1.xlsx")

print("Success")


#python #coding #datascience


Watch video Python Bytes - Openpyxl Add Excel Formula Last Row of Data Across All Columns Code in Description online without registration, duration hours minute second in high quality. This video was added by user AC 22 July 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 837 once and liked it 9 people.