473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use of Excel Interop within C#

I've been tasked to translate a C# program to VB. (Dot Net 2.0.)

I'm starting from scratch with no documentation and I'm trying to understand
what the original programmer did. (The 'original programmer' is conveniently
off on vacation so I can't ask him.) The program deals in some way with Excel
spreadsheets. There is a line of code in the program:

CurSheet =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.

What I don't understand is that get_Item call. It leads to something
labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.

I have no idea how or why this file was generated. Has anyone else out
there ever seen anything like this? What techniques are being used here?

Aug 25 '08 #1
5 1907
From the looks of it he's getting the current sheet off of the file in
that directory (something like the default sheet).
If he's not getting the default sheet then it looks like he's getting
a reference to a sheet. Unfortunately the Excel interop class was
really designed for VB so I coded all my excel processes into a VB.NET
dll and accessed it from C#. This means that the constructors have
like 15 elements and in VB they're optional.
Aug 25 '08 #2
B. Chernick used his keyboard to write :
I've been tasked to translate a C# program to VB. (Dot Net 2.0.)

I'm starting from scratch with no documentation and I'm trying to understand
what the original programmer did. (The 'original programmer' is conveniently
off on vacation so I can't ask him.) The program deals in some way with Excel
spreadsheets. There is a line of code in the program:

CurSheet =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.

What I don't understand is that get_Item call. It leads to something
labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.

I have no idea how or why this file was generated. Has anyone else out
there ever seen anything like this? What techniques are being used here?
Just looking at the words in the code (and having seen Excel) it seems
that a particular worksheet is selected from the entire workbook, based
on some "driverName ". This selected worksheet is assinged to the
variable CurSheet.

I'm guessing that a "correcter" C# syntax would be
CurSheet =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets[driverName];

This (the [] instead of a call to Item) is regular C# to get a specific
item from some list. I just don't know if that still holds with
"interop" calls.

Hans Kesting
Aug 25 '08 #3
If all you're doing is reading data from excel (which will greatly simplify
your life), then abandon the interop.

google something like this

Excel LoadDataSet "select * from [Sheet1$]"

Or you can go here:
http://sholliday.space s.live.com/blog/cns!A68482B9628 A842A!176.entry
and find the code in there (somewhere). Code is downloadable.
If the developer is coming back, then wait for him to come back. That
excel interop crap is tricky.
Too tricky.

"B. Chernick" <BC*******@disc ussions.microso ft.comwrote in message
news:D1******** *************** ***********@mic rosoft.com...
I've been tasked to translate a C# program to VB. (Dot Net 2.0.)

I'm starting from scratch with no documentation and I'm trying to
understand
what the original programmer did. (The 'original programmer' is
conveniently
off on vacation so I can't ask him.) The program deals in some way with
Excel
spreadsheets. There is a line of code in the program:

CurSheet =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.

What I don't understand is that get_Item call. It leads to something
labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.

I have no idea how or why this file was generated. Has anyone else out
there ever seen anything like this? What techniques are being used here?

Aug 25 '08 #4
I'm not absolutely sure I understand your response. However I've found
something that might make things simpler. That file in the temp directory is
definitely 'temp'. It only appears when I do a 'Go To Definition' and
vanishes when I close the project. I've also checked the project properties
to make sure there aren't any exotic references or declarations. (Looks
fairly standard. As far as I can tell the C# and VB project properties are
identical.)

Given that, my only mystery (I think) is why the C# line

CurSheet =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

does not want to translate into VB, given that both projects have the same
reference to the interop and both use the same declared variables?

Still trying. I get the feeling I'm missing something simple.

"cfps.Christian " wrote:
From the looks of it he's getting the current sheet off of the file in
that directory (something like the default sheet).
If he's not getting the default sheet then it looks like he's getting
a reference to a sheet. Unfortunately the Excel interop class was
really designed for VB so I coded all my excel processes into a VB.NET
dll and accessed it from C#. This means that the constructors have
like 15 elements and in VB they're optional.
Aug 25 '08 #5
That's probably the solution. When I changed the C# to WorkSheet[driverName]
and ran it through the translator, I got this:

CurSheet = DirectCast(WB.W orksheets.Item( driverName),
Microsoft.Offic e.Interop.Excel .Worksheet)

No apparent errors.

(The programmer has admited that the original code is not a finished product.)

Thanks.

"Hans Kesting" wrote:
B. Chernick used his keyboard to write :
I've been tasked to translate a C# program to VB. (Dot Net 2.0.)

I'm starting from scratch with no documentation and I'm trying to understand
what the original programmer did. (The 'original programmer' is conveniently
off on vacation so I can't ask him.) The program deals in some way with Excel
spreadsheets. There is a line of code in the program:

CurSheet =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.

What I don't understand is that get_Item call. It leads to something
labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.

I have no idea how or why this file was generated. Has anyone else out
there ever seen anything like this? What techniques are being used here?

Just looking at the words in the code (and having seen Excel) it seems
that a particular worksheet is selected from the entire workbook, based
on some "driverName ". This selected worksheet is assinged to the
variable CurSheet.

I'm guessing that a "correcter" C# syntax would be
CurSheet =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets[driverName];

This (the [] instead of a call to Item) is regular C# to get a specific
item from some list. I just don't know if that still holds with
"interop" calls.

Hans Kesting
Aug 25 '08 #6

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

Similar topics

17
6351
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
1
3044
by: Bernd Muent | last post by:
Hi together, I am using the following code in Visual Basic to open Word or Excel applications: Word: Dim w As Word.Application w = CType(CreateObject("Word.application"), Word.Application) w.Application.Documents.Open("test.doc") With w.Application.Selection
3
9929
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel (SP1) installed. The error is: System.Runtime.InteropServices.COMException(0x800A03EC): Exception from HRESULT: 0x800A03EC. at Microsoft.Office.Interop.Excel._Worksheet.Paste(Object Destination, Object Link) at...
5
3157
by: Mike in Santa Rosa | last post by:
I'm trying to get a simple c# app built that can launch/manipulate an excel workbook, sheet. I've chased down several examples and can't any of them to work. So I must be doing somethnig obviouslt wrong. Most examples to get things started include something: using Microsoft.Office.Interop.Excel; or using Excel; or using Excel = Microsoft.Office.Interop.Excel;
5
2288
by: =?Utf-8?B?U3R1YXJ0?= | last post by:
Hi There I have been having a play around with the following code to display a datagrid in Excel (all from Steve Orr's site): Private Sub btnTechServAccred_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTechServAccred.Click Dim AcredDT As DataTable = UserSession.Current.AcredTable Dim aExcel As New Microsoft.Office.Interop.Excel.Application
0
2353
by: Nicholas Dreyer | last post by:
Operating System: Microsoft Windows Version 5.1 (Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) Visual Basic: MIcrosoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 Forms3: 11.0.6550 (comes with Excel 2003) The copy paste code below fails to copy the PrefixCharacter from cell "a1" to cell "a2" when compiled into a dll and called from VBA, yet running from a VB.NET main program the PrefixCharacter is copied, as it is...
2
4929
by: Nicholas Dreyer | last post by:
The following error Run-time exception thrown : System.Runtime.InteropServices.COMException - Error loading type library/DLL. happens while running the code listed at the bottom of this message in the environment shown here: Operating System: Microsoft Windows Version 5.1 (Build
0
2713
by: jwmaiden | last post by:
Have an application that opens up a webbrowser control to display data in an Excel spreadsheet (using VB.NET in VS 2005). No problem with opening the spreadsheet or displaying the data, but I'm having problems with repeating the process. I want to create an Excel spreadsheet, add some data to it, and display the results in a webbrowser control. I want to be able to then later delete the old Excel spreadsheet, create a new one, add some new data,...
6
1943
by: yoavyoavyoav | last post by:
Hi There , I have an application that creates a csv file and I want it to display it in excel after creation. I've used to following code - which works well : using ExcelInterop = Microsoft.Office.Interop.Excel; ExcelInterop._Worksheet ExcelWorkSheet; //represents the resulting worksheet.
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.