473,216 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

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.Office.Interop.Excel.Worksheet)WB.Works heets.get_Item(driverName);

where CurSheet is 'Microsoft.Office.Interop.Excel.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$Excel.dll$v1.1.4322. The
file name itself is Microsoft.Office.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 1883
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.Office.Interop.Excel.Worksheet)WB.Works heets.get_Item(driverName);

where CurSheet is 'Microsoft.Office.Interop.Excel.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$Excel.dll$v1.1.4322. The
file name itself is Microsoft.Office.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.Office.Interop.Excel.Worksheet)WB.Works heets[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.spaces.live.com/blog/cns!A68482B9628A842A!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*******@discussions.microsoft.comwrote in message
news:D1**********************************@microsof t.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.Office.Interop.Excel.Worksheet)WB.Works heets.get_Item(driverName);

where CurSheet is 'Microsoft.Office.Interop.Excel.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$Excel.dll$v1.1.4322. The
file name itself is Microsoft.Office.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.Office.Interop.Excel.Worksheet)WB.Works heets.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.Worksheets.Item(driverName),
Microsoft.Office.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.Office.Interop.Excel.Worksheet)WB.Works heets.get_Item(driverName);

where CurSheet is 'Microsoft.Office.Interop.Excel.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$Excel.dll$v1.1.4322. The
file name itself is Microsoft.Office.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.Office.Interop.Excel.Worksheet)WB.Works heets[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
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
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)...
3
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...
5
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...
5
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,...
0
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:...
2
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...
0
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...
6
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 =...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.