Show code in...     

  

 

All Functions Math Functions String Functions Logical Functions
Time Functions Statistical Functions Information Functions
Lookup & Reference Functions Database Functions Financial Functions

Math Functions

The only functions available in
ExcelWriterSE and ExcelWriterLE
are sum and average.

Math Functions
abs*

Returns the absolute value of a number. In the following example, b8 will contain the absolute value of the number in cell b7.

ws.Cells("b8").Formula = "=abs(b7)"
acos*

Returns the arccosine, or inverse cosine, of a number. Acos takes one argument, number, which is the cosine of the angle returned by acos. Number must be a value from -1 to 1.

The angle returned by acos is given in radians in the range 0 (zero) to pi. To convert the result from radians to degrees, multiply it by 180/pi(), or use the degrees function.

In the following example, the arccosine is the angle whose cosine is 0.5.

ws.Cells("b8").Value = 0.5
ws.Cells("b8").Formula = "=acos(b7)"
asin*

Returns the arcsine, or inverse sine, of a number. Asin takes one argument, number, which is the sine of the angle returned by asin. Number must be a value from -1 to 1.

The angle returned by asin is given in radians in the range -pi/2 to pi/2. To convert the result from radians to degrees, multiply it by 180/pi(), or use the degrees function.

In the following example, the arcsine is the angle whose sine is 0.3.

ws.Cells("b8").Value = 0.3
ws.Cells("b8").Formula = "=asin(b7)"
atan*

Returns the arctangent, or inverse tangent, of a number. Atan takes one argument, number, which is the tangent of the angle returned by atan.

The angle returned by atan is given in radians in the range -pi/2 to pi/2. To convert the result from radians to degrees, multiply it by 180/pi(), or use the degrees function.

In the following example, the arctangent is the angle whose tangent is 1.

ws.Cells("b8").Value = 1
ws.Cells("b8").Formula = "=atan(b7)"
atan2*

Returns the arctangent, or inverse tangent, of specified x and y coordinates. The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a point with coordinates (x_num, y_num).

A positive atan2 result represents a counterclockwise angle from the x-axis; a negative result represents a clockwise angle. Atan2(a,b) equals atan(b/a), except that a can equal 0 in atan2. If both x_num and y_num are 0, atan2 returns the #DIV/0! error value.

The angle returned by atan2 is given in radians between -pi and pi, excluding -pi. To convert the result from radians to degrees, multiply it by 180/pi(), or use the degrees function. The following returns the arctangent of the point 1,1 (the angle between the x-axis and the line from the origin to point 1,1) in degrees (45).

ws.Cells("b8").Formula = "=degrees(atan2(1,1))"
ceiling*

Returns a number rounded up, away from zero, to the nearest multiple of significance. For example, if you want to avoid using pennies in your prices and your product is priced at $4.42, use the formula ceiling(4.42,0.05) to round prices up to the nearest nickel.

Ceiling takes two arguments, Number and Significance. Number is the value to round up, and Significance is the multiple to which you want to round. If number is an exact multiple of significance, no rounding occurs. If either argument is not a number, ceiling returns the #VALUE! error value.

Regardless of the sign of number, a value is rounded up when adjusted away from zero. If number and significance have different signs, ceiling returns the #NUM! error value.

The following rounds 3.21 up to 3.25.

ws.Cells("b8").Formula = "=ceiling(3.21,0.05)"
cos*

Returns the cosine of a specified angle. Cos takes one argument, Number, which is the angle in radians for which to return the cosine. If the angle is in degrees, multiply it by pi()/180 or use the radians function to convert it to radians.

ws.Cells("b8").Formula = "=cos(radians(45))"
degrees*

Converts radians into degrees. Degrees takes one argument, angle, which is the angle in radians to convert. The following takes pi radians and returns 180 degrees.

ws.Cells("f5").Formula = "=degrees(pi())"
even*

Returns a number rounded up to the nearest even integer. Even takes one argument, Number, which the is the value to round up. You can use this function for processing items that come in twos. For example, a packing crate accepts rows of one or two items. The crate is full when the number of items, rounded up to the nearest two, matches the crate's capacity.

If the value passed to even is not a number, the function returns the #VALUE! error value. Regardless of the sign of the Number argument, a value is rounded up when adjusted away from zero. If number is an even integer, no rounding occurs.

The following displays 32 in cell f5.

ws.Cells("f5").Formula = "=even(31)"
exp*

Returns e raised to the power of the argument. The constant e equals 2.71828182845904, the base of the natural logarithm. In the following example, b8 will contain b7 raised to the power of e.

	ws.Cells("b8").Formula = "=exp(b7)" 
	
fact*

Returns the factorial of a number. The factorial of a number is equal to 1*2*3*...* number. Fact takes one argument, Number, which is the nonnegative number for which to return the factorial. If the argument is not an integer, it is truncated.

The following displays 24 (1*2*3*4) in cell c5.

ws.Cells("c5").Formula = "=fact(4)"
floor*

Rounds a specified number down, toward zero, to the nearest multiple of significance. Floor takes two arguments, Number and Significance. Number is the value to round down. Significance is the multiple to which you want to round.

If either argument is nonnumeric, floor returns the #VALUE! error value. If Number and Significance have different signs, floor returns the #NUM! error value. Regardless of the sign of number, a value is rounded down when adjusted away from zero. If number is an exact multiple of significance, no rounding occurs.

The following rounds 3.27 down to 3.25.

ws.Cells("b8").Formula = "=floor(3.27,0.05)"
int*

Rounds a number down to the nearest integer. In the following example, b8 will contain the value of b7, rounded down to the nearest integer.

	ws.Cells("b8").Formula = "=int(b7)" 
	
ln*

Returns the natural logarithm of a number. Natural logarithms are based on the constant e (2.71828182845904). Ln takes one argument, Number, which is the positive real number for which you want the natural logarithm. Ln is the inverse of exp.

The following returns 4.276666, the natural logarithm of 72.

ws.Cells("b8").Formula = "=ln(72)"
log*

Returns the logarithm of a number to the specified base. Log takes two arguments, Number and Base. Number is the positive real number for which to return the logarithm. Base is the base of the logarithm. If base is omitted, it is assumed to be 10.

The following returns 3, the logarithm of 8 with base 2 (3).

ws.Cells("b8").Formula = "=log(8,2)"
log10*

Returns the base-10 logarithm of a number. Log10 takes one argument, Number, which is the positive real number for which to return the base-10 logarithm.

The following returns 1, the base-10 logarithm of 10.

ws.Cells("b8").Formula = "=log10(10)"
mod*

Returns the remainder after a number is divided. Mod takes two arguments, Number and Divisor. For example, mod(52,5) returns the remainder after dividing 52 by 5, that is, 2. To display this value in cell b6, use

	ws.Cells("b6").Formula = "=mod(52, 5)" 
	
odd*

Returns a number rounded up to the nearest odd integer. Odd takes one argument, Number, which is the value to round up. If the argument is nonnumeric, odd returns the #VALUE! error value. Regardless of the sign of number, a value is rounded up when adjusted away from zero. If number is an odd integer, no rounding occurs.

The following displays 7 in cell f5.

ws.Cells("f5").Formula = "=odd(6)"
pi*

Returns the number 3.14159265358979, the mathematical constant pi, accurate to 15 digits.

product*

Multiplies all the numbers given as arguments and returns the product. Product takes 1 to 30 numbers. Arguments that are numbers, logical values, or text representations of numbers are counted; arguments that are error values or text that cannot be translated into numbers cause errors. If an argument is an array or reference, only numbers in the array or reference are counted. Empty cells, logical values, text, or error values in the array or reference are ignored.

The following multiplies the values in cells h12 to h20, and displays the product in cell h22.

ws.Cells("h22").Formula = "=product(h12:h20,5)"
radians*

Converts degrees to radians. Degrees takes one argument, angle, which is the angle in degrees to convert. The following takes 180 degrees and returns pi radians.

ws.Cells("f5").Formula = "=radians(180)"
round*

Rounds a number to a specified number of digits. In the following example, b6 will contain the value of b5, rounded to 2 decimal places.

	ws.Cells("b6").Formula = "=round(b5, 2)" 
	
rounddown*

Rounds a number down, toward zero. Rounddown takes two arguments Number and Num_digits. Number is the value to round down. Num_digits is the number of digits to which you want to round the number.

If num_digits is greater than 0 (zero), then number is rounded down to the specified number of decimal places. If num_digits is 0, then number is rounded down to the nearest integer. If num_digits is less than 0, then number is rounded down to the left of the decimal point.

The following will round 9.2745 down to 2 decimal places, and display 9.27 in cell f5.

ws.Cells("f5").Formula = "=rounddown(9.2745,2))"
roundup*

Rounds a number up, away from 0 (zero). Roundup takes two arguments Number and Num_digits. Number is the value to round up. Num_digits is the number of digits to which you want to round the number.

If num_digits is greater than 0 (zero), then number is rounded up to the specified number of decimal places. If num_digits is 0, then number is rounded up to the nearest integer. If num_digits is less than 0, then number is rounded up to the left of the decimal point.

The following will round 9.2745 up to 2 decimal places, and display 9.28 in cell f5.

ws.Cells("f5").Formula = "=roundup(9.2745,2))"
sin*

Returns the sine of the given angle. Sin takes one argument, Number, which is the angle in radians for which to return the sine.

If the angle in degrees, multiply it by pi()/180 or use the radians function to convert it to radians.

ws.Cells("b8").Formula = "=sin(radians(45))"
sqrt*

Returns a positive square root. Sqrt takes one argument, Number, which is the number for which to return the square root. If Number is negative, sqrt returns the #NUM! error value.

ws.Cells("b8").Formula = "=sqrt(9)"
subtotal*

Returns the subtotal of a set of cells using a specified function, in a list or database. Subtotal takes as arguments function_num and 1 to 29 cell references or ranges. Function_num is a number from 1 to 11 that represents the function used to calculate the subtotal, as listed in the following table.

average1
count2
counta3
max4
min5
product6
stdev7
stdevp8
sum9
var10
varp11
	'--- Generate a subtotal of B1:B4 using the average function
	ws.cells("B5").formula ="=subtotal(1,B1:B4)"
	
	'--- Generate a subtotal of A1:A4 using the sum function
	ws.cells("A5").formula = "=subtotal(9,A1:A4)"
	
sum

Adds all the numbers in a range of cells. In the following example, the sum of the values in cells b2 through b5 will be displayed in cell b6.

	ws.Cells("b6").Formula = "=sum(b2:b5)" 
	
sumif*

Adds a range of cells if a specified condition is met. Sumif takes three arguments: range, criteria, and sum_range. Range is the set of cells to be evaluated. Criteria is the condition to be met. Sum_range contains the cells to be summed if the corresponding cells in range meet the specified condition. For example, if range A1:A4 contains {32;45;67;23}, the condition is ">44," and sum_range B1:B4 contains {3;7;2;4}, only the second and third members of sum_range (7 and 2) will be summed, because only the second and third members of range (45 and 67) are greater than 44. To display the result of this example (9) in cell B5, use,

	ws.cells("B5").formula = "=sumif(A1:A4,"">44"",B1:B4)"
	

Notice that the embedded string ">44" is within an additional set of double-quotes. ASP syntax requires that double-quotes embedded in a string be doubled. Alternatively, use single quotes:

	ws.cells("B5").formula = "=sumif(A1:A4,'>44',B1:B4)"
	
tan*

Returns the tangent of the given angle. Tan takes one argument, Number, which is the angle in radians for which to return the tangent.

If the angle in degrees, multiply it by pi()/180 or use the radians function to convert it to radians.

ws.Cells("b8").Formula = "=tan(radians(45))"
*This function is not available in ExcelWriterSE, ExcelWriterLE, or ExcelWriterFree. The only functions available in ExcelWriterSE, ExcelWriterLE, and ExcelWriterFree are sum and average.



Copyright © 2005, SoftArtisans, Inc.