473,320 Members | 1,832 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,320 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 1886
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.