I am using the Microsoft .NET Framework SDK v1.1. I am trying to add a reference to the Microsfot Excel Object Library.
Am I correct in assuming this is done by using the reference switch with csc? If it is possible to do with the framwork, what filename should I be passing?
Thanks,
Martin
-
-
Are you trying to message excel like the old COM days? If so I believe that you have to do so using com Interop ( because excel is still a COM application ). We have software in he field that does this every day.
Here is a little snippet of code ripped from one of my test apps that plays with excel extensively. I have not added any references to excel in the references section. I am using Late binding which may or may not be appropriate for you setup. We use late binding because the application needs to be able to run in systems where excel is not installed.
Formatting in this message editor is less than ideal but you should be able to get the point...
Please no flames about the inherant issues in this code I know they are many Its only from one of my test rigs folks....
Here goesDim ex As Object
Dim sh As Object
Dim iRatingIndex As Integer
For iRatingIndex = 0 To sCategories.GetUpperBound(0)
Dim _workbook As Object
Try
ex = CreateObject("Excel.Application")
Catch trouble As Exception
MsgBox(trouble.Message, MsgBoxStyle.Exclamation, "Houston... we have a problem")
Exit Sub
End Try
ex.visible = True
ex.ScreenUpdating = False
' create the 26 worksheets
_workbook = ex.workbooks.add()
While ex.activeworkbook.worksheets.count < 26
ex.workbooks.item("Book1").worksheets.add()
End While
Dim iIndex As Integer
' set the name of each worksheet
For iIndex = 1 To 26
ex.workbooks.item("Book1").worksheets(iIndex).name = Me._worksheets(iIndex).Name
Next
-
I have been using the reference http://support.microsoft.com/default.aspx?kbid=302084.
In instruction 3 it states you need to add a reference to the Microsoft Excel Object Library. As I do not currently own the IDE, I am coding via notepad.
When I compile the program I get the message:
excel.cs(3,25): error CS0234: The type or namespace name 'Office' does not exist in the class or namespace 'Microsoft' (are you missing an assembly reference?)
Line 3 is:
using Excel = Microsoft.Office.Interop.Excel;
This is part of instruction 7 of the MSDN article. -
Found an example which compiles fine within the SDK, just got to study it and work out how to apply it to my program.
-
Did you figure out that you need to create a COM interop assembly?
Check out the .NET Framework Type Library to Assembly Converter: tlbimp.exe
John. -
You should try using the Office PIAs. More info about COM Interop.
-
Yeah, eventually figured out that was what was wrong.
Going to get myself some books on C#, although will have to wait a bit, as had to buy some books for my physics course.
Probably get Visual C#.NET Standard soon as well, but I'll start off with the evaluation copy of Visual Studio I have.
Thanks for all the quick replies -
Is there a reason why you need to create an Excel object?
You can easily have your app output an Excel xml file.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.