I am trying to use excel as a maths engine in a VB.NET application.
I have managed to get the basic functionality I desire, but in doing so
have to open an existing workbook using the following code:
Function CalculateFromEXCEL() As Single
Dim xL As New Excel.Application()
Dim xlWBk As Excel.Workbook()
Dim xLWSht As New Excel.Worksheet()
Dim range As Excel.Range
xL.Workbooks.Open("C:\Test.xls", , False)
xLWSht = xL.Workbooks(1).Worksheets(1)
range = xLWSht.Range("A1", Reflection.Missing.Value)
range = range.Resize(S.GetLength(0), 1)
range.Value = xLArray
Str = "AVERAGE(A1:A" & S.GetLength(0).ToString & ")"
CalculateFromEXCEL = CSng(xL.Evaluate(Str))
xL.Workbooks(1).SaveAs("C:\Test.xls")
xL.Workbooks(1).Saved = True
xL.Workbooks.Close()
xL.Quit
xL= Nothing
End Function
This doesn't seem to be too rigorous as I have to be able to predict the
existence of a suitably formatted workbook ahead of time.
I figure you must be able to avoid this problem by either instatiating a
new EXCEL Application object, assigning a valid workbook and worksheet
and then using this as the basis for calculations or running the EXCEL
application and worksheets etc as background objects.
Dino Chiesa [MSFT] - 15 Sep 2003 23:23 GMT
see the examples in
<netsdk>\Samples\Technologies\Interop\Applications\Office
where <netsdk> is where the .NET SDK is installed, usually something like
c:\Program Files\Microsoft.NET\SDK\v1.1\
> I am trying to use excel as a maths engine in a VB.NET application.
> I have managed to get the basic functionality I desire, but in doing so
[quoted text clipped - 27 lines]
> and then using this as the basis for calculations or running the EXCEL
> application and worksheets etc as background objects.