//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); GrapeCity.Documents.Excel.Workbook.AddCustomFunction(new GeneralID()); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1"].Formula = "GeneralID()"; var valueA1Before = worksheet.Range["A1"].Value; worksheet.Range["A2"].Formula = "GeneralID()"; // A1's value has changed. var valueA1After = worksheet.Range["A1"].Value; /* Implementation of GeneralID public class GeneralID : CustomFunction { public GeneralID() : base("GeneralID", FunctionValueType.Object) { this.IsVolatile = true; } public override object Evaluate(object[] arguments, ICalcContext context) { return Guid.NewGuid().ToString("N"); } } */
' Create a new Workbook Dim workbook As New Workbook Excel.Workbook.AddCustomFunction(New GeneralID()) Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("A1").Formula = "GeneralID()" Dim valueA1Before = worksheet.Range("A1").Value worksheet.Range("A2").Formula = "GeneralID()" ' A1's value has changed. Dim valueA1After = worksheet.Range("A1").Value ' Implementation of GeneralID ' ' public class GeneralID : CustomFunction ' { ' public GeneralID() : base("GeneralID", FunctionValueType.Object) ' { ' this.IsVolatile = true; ' } ' ' public override object Evaluate(object[] arguments, ICalcContext context) ' { ' return Guid.NewGuid().ToString("N"); ' } ' }