Arithmetic Operation on Spreadsheet
Arithmetic operations can be performed by typing the formula in a particular cell of the spreadsheet. For example, if we want to find the sum then =Sum() formula of the excel file is used.
Example:
In this example, the openpyxl module is used to create a new Excel workbook and populate cells A1 to A5 with numeric values. Cell A7 is assigned a formula to calculate the sum of the values in A1 to A5.
Python3
# import openpyxl module import openpyxl wb = openpyxl.Workbook() sheet = wb.active # writing to the cell of an excel sheet sheet[ 'A1' ] = 200 sheet[ 'A2' ] = 300 sheet[ 'A3' ] = 400 sheet[ 'A4' ] = 500 sheet[ 'A5' ] = 600 sheet[ 'A7' ] = '= SUM(A1:A5)' # save the file wb.save( "sum.xlsx" ) |
Output:
Refer to the below article to get detailed information about the Arithmetic operations on Spreadsheet.
Working with Excel Spreadsheets in Python
You all must have worked with Excel at some time in your life and must have felt the need to automate some repetitive or tedious task. Don’t worry in this tutorial we are going to learn about how to work with Excel using Python, or automating Excel using Python. We will be covering this with the help of the Openpyxl module and will also see how to get Python in Excel.