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 / Visual Studio.NET / VS Tools for Office / March 2008

Tip: Looking for answers? Try searching our database.

How to interact with Excel 2007 from Winforms app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ole_Brun - 03 Mar 2008 19:06 GMT
Hi

I am creating a winforms app in vb.net using Visual Studio 2008.
I want to open an existing Excel 2003 file, and update some data, and I  
don't want to create a workbook project or add-in.
What I want is my stand-alone application that can talk to any Excel file  
and update values.

Can anyone tell me how to open a workbook first of all?
I have added references to:
- Microsoft.Office.Interop.Excel
- Microsoft.Office.Tools.Common.v9.0
- Microsoft.Office.Tools.Excel.9.0
- Microsoft.Office.Tools.v9.0
- Microsoft.VisualStudio.Tools.Office.Runtime.v9.0
- Office

I have ound the Workbook type under Microsoft.Office.Tools, but then I  
don't know how to open an existing file.

Seems like all examples on the internet assumes that you create a Workbook  
project.

Thanx for any help!

-Ole_Brun

Signature

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Ivan A. Vasilyev - 04 Mar 2008 04:22 GMT
Hello.

You do not need VSTO (Microsoft.Office.Tools/Microsoft.VisualStudio.Tools
namespaces) at all to automate Excel.
Just use Office2003 PIA
(http://www.microsoft.com/downloads/details.aspx?FamilyID=3c9a983a-ac14-4125-8ba0
-d36d67e0f4ad&DisplayLang=en
).
Apparently you already have PIA installed cause you mentioned
Microsoft.Office.Interop.Excel namespace.

To open existing XLS file:
 Dim excelApp as Microsoft.Office.Interop.Excel.Application
 excelApp = new Microsoft.Office.Interop.Excel.Application()
 Dim workbook as Microsoft.Office.Interop.Excel.Workbook
 Dim missing as Object
 missing = Missing.Value
 workbook = excelApp.Workbooks.Open("PATH_TO_XLS", missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing)

To update data use Object Model of workbook:
 Dim firstSheet as Microsoft.Office.Interop.Excel.Worksheet
 firstSheet = workbook.Sheets(1)
 firstSheet.Cells(1, 1).Value2 = "Set some text for Cell:1:1"
 ...etc

But be aware of the BUG when automating Excel without VSTO:
http://support.microsoft.com/?scid=kb%3Ben-us%3B320369&x=15&y=12

Good luck
Ivan

> Hi
>
[quoted text clipped - 22 lines]
>
> -Ole_Brun
Ole_Brun - 04 Mar 2008 06:59 GMT
Thanks a lot Ivan!

I will try what you are suggesting.

But then my question will be; is it possible to use VSTO from an external  
application, or do you have to use it in an Excel project?

-Ole_Brun

> Hello.
>
[quoted text clipped - 58 lines]
>> --
>> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Signature

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Ivan A. Vasilyev - 04 Mar 2008 07:26 GMT
> But then my question will be; is it possible to use VSTO from an external
> application, or do you have to use it in an Excel project?

I think VSTO is not intended for use out of projects of specific types. I
mean application- and document-level extensions projects.
But some reuse of VSTO is possible. E.g. you could reuse
ExcelLocale1033Proxy class
(http://msdn2.microsoft.com/en-us/library/microsoft.office.tools.excel.excellocal
e1033proxy.aspx
)
to work around Excel bug mentioned in previous post.
But any reuse of VSTO makes an deployment process heavier. I.e. you should
have VSTO installed on a deployment machine for your app to work.

Best regards.
Ivan.
Ole_Brun - 05 Mar 2008 07:50 GMT
Thank you Ivan!
Now things are more clear to me.

Cheers,
Ole_Brun

>> But then my question will be; is it possible to use VSTO from an  
>> external
[quoted text clipped - 12 lines]
> Best regards.
> Ivan.

Signature

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Ivan A. Vasilyev - 04 Mar 2008 07:48 GMT
I missed the Office version you use and gave you wrong PIA url.

For Office 2007 it is better to use "native" PIAs. Here is the right url
http://www.microsoft.com/downloads/details.aspx?FamilyID=59daebaa-bed4-4282-a28c
-b864d8bfa513&DisplayLang=en


PS. But PIAs are backward compatible so it is possible to use earlier
version if you need to support different Office versions in your solution.
E.g. you could use Office 2003 PIA to build single solution supporitng both
Office 2003 and Office 2007.

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.