Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

EXCEL Automation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andrew allan - 10 Sep 2003 07:48 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.