Imports System
Imports System.Diagnostics
Imports SpreadsheetGear
Imports SpreadsheetGear.Advanced.Cells
Namespace SpreadsheetGear.AdvancedCellValueSample
_
Class Program
' Demonstrate the use of advanced cell values APIs.
Shared Sub Main()
' Create a new workbook and get it's worksheet.
Dim workbook As IWorkbook = Factory.GetWorkbook()
Dim worksheet As IWorksheet = workbook.Worksheets(0)
' Get the SpreadsheetGear.Advanced.Cells.IValues
' interface from the worksheet.
Dim values As IValues = CType(worksheet, IValues)
' Set short month names in B1, C1 and D1 and verify
' using SpreadsheetGear.Advanced.Cells.IValue.
values.SetText(0, 1, "Jan")
Debug.Assert(values(0, 1).Text.Equals("Jan"))
values.SetText(0, 2, "Feb")
Debug.Assert(values(0, 2).Text.Equals("Feb"))
values.SetText(0, 3, "Mar")
Debug.Assert(values(0, 3).Text.Equals("Mar"))
' Set names in A2, A3 and A4 and verify.
values.SetText(1, 0, "Mary")
Debug.Assert(values(1, 0).Text.Equals("Mary"))
values.SetText(2, 0, "Mike")
Debug.Assert(values(2, 0).Text.Equals("Mike"))
values.SetText(3, 0, "Miles")
Debug.Assert(values(3, 0).Text.Equals("Miles"))
' Set some numeric values in B2:D4 and verify.
Dim column As Integer
For column = 1 To 3
Dim columnSum As Double = 0.0
Dim row As Integer
For row = 1 To 3
Dim number As Double = row * 10 + column
values.SetNumber(row, column, number)
Debug.Assert((values(row, column).Number = number))
columnSum += number
Next row
' Set formulas which sum the month, verify the
' formula was set and verify the formula result
' is correct.
Dim formula As String = "=SUM(" + workbook.WorkbookSet.GetAddress(1, column) + ":" + workbook.WorkbookSet.GetAddress(3, column) + ")"
values.SetFormula(4, column, formula)
Dim val As IValue = values(4, column)
Debug.Assert((Not (val Is Nothing)))
Debug.Assert(val.HasFormula)
Debug.Assert(val.Formula.Equals(formula))
Debug.Assert((val.Type = Advanced.Cells.ValueType.Number))
Debug.Assert((val.Number = columnSum))
Next column
End Sub 'Main
End Class 'Program
End Namespace 'SpreadsheetGear.AdvancedCellValueSample