473,473 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Load Excel in VB.Net

Hi, anyone know how to load excel in vb.net? I trying to load a template
with formula so that i can save to access.

Regards,
PCK
Dec 23 '05 #1
3 5086
I use the following code to open excel file:

Private _excel As Excel.Application
Private _book As Excel.Workbook
Private _readOnly As Boolean = False

Private Sub openExcelFile(ByVal fileName As String)
' There is no error handling here: it has to be present in the
calling procedure
If _excel Is Nothing Then
_excel = New Excel.Application
_excel.Visible = False
End If
_book = _excel.Workbooks.Open(fileName:=fileName,
ReadOnly:=_readOnly, Notify:=False)
End Sub

HTH

"Phoon Chee Keong" wrote:
Hi, anyone know how to load excel in vb.net? I trying to load a template
with formula so that i can save to access.

Regards,
PCK

Dec 23 '05 #2
Phoon,

Forgot to mention: the code in the previous code is part of a class that
deals with that specific workbook. It also contains the following code:

Implements IDisposable

Public Sub Dispose() Implements IDisposable.Dispose
If Not _book Is Nothing Then
_book = Nothing
End If
If Not _excel Is Nothing Then
With _excel
' This particular instance of Excel was open for our work
only:
For Each wrk As Excel.Workbook In .Workbooks
wrk.Close(SaveChanges:=False)
Next
.Quit()
End With
_excel = Nothing
End If

When you create instances of your class, wrap them in Try..Catch..Finally
block and put code similar to the following into Finally:

If Not MyExcelClass Is Nothing Then
MyExcelClass.Dispose()
MyExcelClass = Nothing
End If

This is important, so that you do not have 'ghost' excel instances hanging
around after your application is closed.

"Phoon Chee Keong" wrote:
Hi, anyone know how to load excel in vb.net? I trying to load a template
with formula so that i can save to access.

Regards,
PCK

Dec 23 '05 #3
TQ HTH

Do u have any sample code on this? Maybe can load into flexgrid.

Regards
PCK

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com> wrote
in message news:24**********************************@microsof t.com...
Phoon,

Forgot to mention: the code in the previous code is part of a class that
deals with that specific workbook. It also contains the following code:

Implements IDisposable

Public Sub Dispose() Implements IDisposable.Dispose
If Not _book Is Nothing Then
_book = Nothing
End If
If Not _excel Is Nothing Then
With _excel
' This particular instance of Excel was open for our work
only:
For Each wrk As Excel.Workbook In .Workbooks
wrk.Close(SaveChanges:=False)
Next
.Quit()
End With
_excel = Nothing
End If

When you create instances of your class, wrap them in Try..Catch..Finally
block and put code similar to the following into Finally:

If Not MyExcelClass Is Nothing Then
MyExcelClass.Dispose()
MyExcelClass = Nothing
End If

This is important, so that you do not have 'ghost' excel instances hanging
around after your application is closed.

"Phoon Chee Keong" wrote:
Hi, anyone know how to load excel in vb.net? I trying to load a template
with formula so that i can save to access.

Regards,
PCK

Dec 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vincent | last post by:
I am trying to generate Excel worksheets using .Net. The worksheets are actually HTML pages with Excel specific XML elements. Everything works fine until I added these following code in the...
1
by: chris | last post by:
Hi there, I load an excel file from an asp.net page and try to read it into a dataset. The problem is that it tells me: Database or object is read-only It only needs to be read only. Here is the...
4
by: Li Pang | last post by:
Hi, Instead of openning an Excel Worksheet from a file, I set the content of the file into a string (stays in the memory) and I'd like to load it into an Excel Worksheet. Anybody knows how? ...
1
by: Lucky | last post by:
hi guys, i've just started woth Excel component in .NET. i manged to import the Excel Component on windows Forms but i'm not able to load Excel file in that. if anyone has any idea how can this be...
0
by: Jack | last post by:
Hi, We built a COM object(let say, rtblink.dll) and extend RTD function by implementing IRtdServer in our coding. The platform was .Net 1.1 , and IDE is Visual Studio7.0. We use regasm to pu the...
0
by: prabhu_27_84 | last post by:
while i am trying to this thing (richtextbox1.loadfile(openfiledialog1.filename,richtextboxstreamtype.plaintext) this will load text file to richtextbox1.i like to load excel file.how can i do...
6
by: kirke | last post by:
Hi, I want to load excel. However, this simple code doesn't work. When I open this page, there's nothign happen, not even 'unable to initiate excel" or othere error message. I have excel in...
0
by: wankhusairi | last post by:
hello for your imformation im using Vb6 and having difficulties on loading a file and then displayed the file. for your information i uses a combox,listview ,directory view and also command buttons...
1
by: =?Utf-8?B?dHRocm9uZQ==?= | last post by:
Hi, I am querying sql server and loading the resulting data into Excel. For character and integer data types, it's working well, but when I pull decimal data and attempt to load it into Excel...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.