使用openpyxl在excel文件中进行Python |三角运算

先决条件: 调整行和列 使用openpyxl创建excel工作表。

null

Openpyxl 是一个Python库,使用它可以对excel文件执行多种操作,如 阅读 , , 数学的 运营和 绘制图形 .让我们看看如何使用openpyxl执行不同的三角运算。

简单三角函数:

代码#1: 在程序中使用简单的三角函数。

  • =SIN(数字): 返回角度的正弦值。数字是以弧度为单位的角度,需要正弦。
  • =COS(编号): 返回角度的余弦。
  • =谭(数字): 返回角度的切线。
  • =CSC(编号): 返回角度的余割。
  • =秒(数字): 返回一个角度的正割。
  • =COT(编号): 返回角度的余切。

# import openpyxl module
import openpyxl
# Call a Workbook() function of openpyxl
# to create a new blank Workbook object
wb = openpyxl.Workbook()
# Get workbook active sheet
# from the active attribute.
sheet = wb.active
# set the width of the column
sheet.column_dimensions[ 'A' ].width = 20
sheet.column_dimensions[ 'B' ].width = 30
sheet.column_dimensions[ 'C' ].width = 20
# writing to the cell of an excel sheet
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"
sheet[ 'B5' ] = "Cosecant"
sheet[ 'B6' ] = "Secant"
sheet[ 'B7' ] = "Cotangent"
# The value in cell C1 to C7 is set to a formula
# that calculates values for particular 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 the file
wb.save( "simple_trigonometric.xlsx" )


输出: 图片[1]-使用openpyxl在excel文件中进行Python |三角运算-yiteyi-C++库

代码#2: 在程序中使用双曲三角函数。

  • =SINH(数字): 返回数字的双曲正弦。
  • =COSH(数字): 返回数字的双曲余弦。
  • =TANH(数字): 返回数字的双曲正切。
  • =CSCH(编号): 返回数字的双曲余割。
  • =秒(数字): 返回数字的双曲正割。
  • =科思(编号): 返回数字的双曲余切。

# import openpyxl module
import openpyxl
# Call a Workbook() function of openpyxl
# to create a new blank Workbook object
wb = openpyxl.Workbook()
# Get workbook active sheet
# from the active attribute.
sheet = wb.active
# set the width of the column
sheet.column_dimensions[ 'A' ].width = 20
sheet.column_dimensions[ 'B' ].width = 30
sheet.column_dimensions[ 'C' ].width = 20
# writing to the cell of an excel sheet
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 cell C1 to C7 is set to a formula
# that calculates values for particular 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 the file
wb.save( "Hyperbolic_trigonometric.xlsx" )


输出: 图片[2]-使用openpyxl在excel文件中进行Python |三角运算-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享