Change language

Python | Trigonometric operations in an excel file using openpyxl

| | |

Openpyxl — it is a Python library with which you can perform several operations on Excel files like writing , math operations and plotting . Let’s see how to perform various trigonometric operations using openpyxl.

Simple trigonometric functions:

Code # 1: Using simple trigonometric functions in the program.

  • = SIN (Number): Returns the sine of an angle. The number — this is the angle in radians for which you want the sine.
  • = COS (Number): returns the cosine of the angle.
  • = TAN (Number ): Returns the tangent of an angle.
  • = CSC (number): Returns the cosecant at an angle.
  • = SEC (Number) : returns the cutting angle.
  • = COT (Number): returns the cotangent of the angle.

# import openpyxl module

import openpyxl

 
# Calling the Workbook () function from openpyxl
# create a new blank Workbook object

wb = openpyxl.Workbook ()

  
# Get worksheet of active sheet
# from active attribute.

sheet = wb.active

 
# set column width

sheet. column_dimensions [ ’A’ ]. width = 20

sheet.column_dimensions [ ’B’ ]. width = 30

sheet.column_dimensions [ ’C’ ]. width = 20

  
# write to Excel sheet cell

sheet [ ’A1’ ] = "angles in radian"

sheet [ ’A2’ ] = 0.1

sheet [ ’A3’ ] = 0.2

sheet [ ’A4’ ] = 0.3

sheet [ ’A5’ ] = 0.4

sheet [ ’A6’ ] = 0.5

sheet [ ’ A7’ ] = 0.6

  
# mention performing trigonometric operations

sheet [ ’ B1’ ] = "Applying trigonometric function"

sheet [ ’B2’ ] = "Sine"

sheet [ ’B3’ ] = "Cosine"

sheet [ ’B4’ ] = "Tangent" < / code>

sheet [ ’B5’ ] = "Cosecant"

sheet [ ’B6’ ] = "Secant"

sheet [ ’B7’ ] = "Cotangent"

 
# The value in cells C1 to C7 is set by the formula
#, which calculates values ​​for a specific radian.

sheet [ ’C1’ ] = ’corresponding values’

sheet [ ’C2’ ] = ’= SIN (0.1)’

sheet [ ’C3’ ] = ’= COS (0.2)’

sheet [ ’C4’ ] = ’ = TAN (0.3) ’

sheet [ ’ C5’ ] = ’ = CSC (0.4) ’

sheet [ ’C6’ ] = ’= SEC (0.5)’

sheet [ ’C7’ ] = ’ = COT (0.6) ’

  
# save file

wb.save ( "simple_trigonometric.xlsx" )

Exit:

Code # 2: Using hyperbolic trigonometric functions in the program.

  • = SINH (Number): returns the hyperbolic sine of a number.
  • = COSH (Number): returns the hyperbolic cosine of a number.
  • = TANH (Number): Returns the hyperbolic tangent of a number.
  • = CSCH (Number): Returns the hyperbolic cosecant of a number.
  • = SECH (number): returns the hyperbolic secant of a number.
  • = COTH (number): returns gives the hyperbolic cotangent of a number.

# import openpyxl module

import openpyxl

 
# Calling the Workbook () function from openpyxl
# create a new empty Workbook object

wb = openpyxl.Workbook ()

 
# Get the worksheet of the active sheet
# from the active attribute.

sheet = wb.active

 
# set column width  

sheet.column_dimensions [ ’A’ ]. width = 20

sheet.column_dimensions [ ’B’ ]. width = 30

sheet.column_dimensions [ ’ C’ ]. width = 20

 
# writing to an Excel sheet cell

sheet [ ’A1’ ] = " angles in radian "

sheet [ ’ A2’ ] = 0.1

sheet [ ’A3’ ] = 0.2

sheet [ ’A4’ ] = 0.3

sheet [ ’A5’ ] = 0.4

sheet [ ’A6’ ] = 0.5

sheet [ ’A7’ ] = 0.6

 
# mention performing trigonometric operations

sheet [ ’B1’ ] = " Applying trigonometric function "

sheet [ ’ B2’ ] = "Hyperbolic Sine"

sheet [ ’B3’ ] = " Hyperbolic Cosine "

sheet [ ’ B4’ ] = "Hyperbolic Tangent"

sheet [ ’B5’ ] = "Hyperbolic Cosecant"

sheet [ ’B6’ ] = "Hyperbolic Secant"

sheet [ ’B7’ ] = "Hyperbolic Cotangent"

 
# The value in cells C1 to C7 is set by the formula
# that calculates values ​​for a specific radian.

sheet [ ’C1’ ] = ’corresponding values’

sheet [ ’C2’ ] = ’= SINH (0.1)’

sheet [ ’ C3’ ] = ’= COSH (0.2)’

sheet [ ’C4’ ] = ’= TANH (0.3)’

sheet [ ’C5’ ] = ’ = CSCH (0.4) ’

sheet [ ’C6’ ] = ’= SECH (0.5)’

sheet [ ’C7’ ] = ’= COTH (0.6)’

 
# save file

wb.save ( "Hyperbolic_trigonometric.xlsx" )

Output:

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically