p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   Unable to open excel file thru vb.net (http://p2p.wrox.com/showthread.php?t=26534)

sreeramulu March 8th, 2005 05:36 AM

Unable to open excel file thru vb.net
 
Hi,
    I want to open an existing excel file thru vb.net programmatically. Let me know how to do it.

Sreeramulu

caveatashish January 29th, 2008 09:09 AM

Hi,

Just share the answer with me if you get the reply


lee_suko June 1st, 2008 05:14 AM

        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Open("c:\test1.xlsx")
        xlWorkSheet = xlWorkBook.Worksheets("sheet1")

full src

http://vb.net-informations.com/excel..._open_file.htm




vinod_yadav1919 June 1st, 2008 12:26 PM

Hii sreeramulu!!

Put post in proper forum..
,you may get early response than waiting for long time,its just a suggestion...



Cheers :)

vinod

caveatashish June 2nd, 2010 01:02 AM

Close the file
 
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("c:\test1.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("sheet1")


once you are done with the excel file don't forget to close the file, otherwise it will give an error if you try to open that excel file again either through code or manually

xlApp.Workbooks.Close

RedDotVasilyev December 6th, 2013 04:19 AM

Re: Unable to open excel file thru vb.net
 
Hi, just to add to a caveatashish's answer, when you are finished with your spreadsheet’s tasks it is not enough to close the file. You need to release every COM object which was created and quit the application, you can read more about this on this discussion:
Code:

xlApp.Quit()
Marshal.ReleaseComObject(xlWorkSheet)
Marshal.ReleaseComObject(xlWorkBook)
Marshal.ReleaseComObject(xlApp)
xlApp = Nothing

Also you can try this simpler approach with a help of this VB.NET library, it has an easy to use API for reading an excel file in .NET and you will not have to bother with releasing the COM objects from the memory.
Code:

Dim xlWorkBook As ExcelFile = ExcelFile.Load("c:\test1.xlsx")
Dim xlWorkSheet As ExcelWorksheet = xlWorkBook.Worksheets("sheet1")



All times are GMT -4. The time now is 09:57 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.