Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introducedin
09.1

Description

Excerpt

The sort method allows a user to sort an area by a particular column in the area. This method can sort numeric, alphabetic, and alphanumeric data. The user can also specify if the area contains headers, and whether to sort by ascending or descending.

Signature
C#
C#
public void IFunction
{
    FunctionValue Calculate(IList<FunctionValue> args, Cell currentCell);
}
Example
Code Block
csharp
csharp
titleC#
//Sort area with headers by the first column ascending 
Area a = WB[0].CreateArea("A1:C6");
a.Sort(0, true, true);
            
//Sort area with headers by first column descending
Area b = WB[0].CreateArea("A10:C15");
b.Sort(0, false, true);
            
//Sort area without headers by the first column ascending
Area c = WB[0].CreateArea("E2:G6");
c.Sort(0, true, false);
            
//Sort area without headers by the first column descending
Area d = WB[0].CreateArea("E11:G15");
d.Sort(0, false, false);
Code Block
vbnet
vbnet
titlevb.net
Class Concat
	Implements IFunction

	//Your custom function should be called Calculate and have the same signature as the sample function below 
	Public Function Calculate(args As IList(Of FunctionValue), currentCell As Cell) As FunctionValue
	        //Implement the custom logic you want to calculate your custom/overridden Excel function 		
                Dim result As New StringBuilder("")
		For Each arg As FunctionValue In args
			result.Append(",")

			Select Case arg.Type
				Case FunctionValueType.[BOOLEAN]
					result.Append(If(CBool(arg.Value), "True", "False"))
					Exit Select
				Case FunctionValueType.[STRING]
					result.Append(arg.Value)
					Exit Select
				Case FunctionValueType.NUMBER
					result.Append(CDbl(arg.Value).ToString("0.#####"))
					Exit Select
				Case FunctionValueType.NULL
					result.Append(" ")
					Exit Select
				Case FunctionValueType.RANGE
					result.Append(arg.Value.ToString())
					Exit Select
			End Select
		Next

 		//Must return a FunctionValue object
		Return New FunctionValue(result.ToString())
	End Function
End Class