Using excel in c# - c#

I'm running Visual Studio 2010 Express, and in C# I'm trying to display Excel workbook.
I'm trying to use
Microsoft.Office.Interop.Excel
I have office 2007. Why doesn't this show up when I go to add> reference and navigate to the .NET or COM tabs?
Why doesn't this show up?
How can I add this as a reference or is there a better to show a workbook to the user in Excel?

For whatever reason VS 2010 doesn't like to show it in the .NET tab of the Add Reference window, you have to manually browse for it. The path to the assembly is C:\Windows\assembly\Microsoft.Office.Interop.Excel.
Go to Add Reference
Click on the Browse tab
Browse to C:\windows\assembly
Choose Microsoft.Office.Interop.Excel

I've had decent luck using EPPlus. It was awhile ago but I chose it since at the time the interop library was specific to a single version of Office whereas epplus was compatible with any version supporting the Open Office Xml format

Related

Cannot add Excel to Project as a COM object

I am needing to create an Excel spreadsheet from a c# project, but I cannot add the reference to the Excel COM object.
I am using Visual Studio 2010 and office 2013. I've clicked on the References folder and selected Add Reference, and then navigated to the COM tab, setting them in alphabetical order. I looked through, but there was no reference to Microsoft.Office.Interop.Excel.
Trying to resolve the issue, I downloaded and installed the PIAs for Office 2010, but references still were not added. I'm not sure where these files would be located on the hard-drive, so I cannot just browse to them (or copy one to the project Resource folder and reference it there).
Does anyone have an idea as to why I cannot see the references?
Additional Information
I managed to get the Microsoft.Office.Interop.dll file from a coworker for Office 2013, but I was not able to reference it from my project since I am working in .NET 3.5. My manager does not want me to update the project to .NET 4.0, so it looks like I will need to use the Office 2010 PIAs I installed. Unfortunately, installing them did not add them to the list, and I haven't been able to find the dll's to add them by browsing to them.
I doubt that it will make a difference, but my dev system is Windows 8.

How to include a dynamic link library in my setup?

I have written a program, where I use the Microsoft.Office.Interop.Excel library. Now I want to create (my first) setup of this program. I use the setup project of Visual studio,
Everything works great, but now I have to include the Microsoft.Office.Interop.Excel.dll to my setup, so if Microsoft excel isn't installed to the computer he can also use my program...
How can I do that?
In your project, in Solution Explorer, right click your project name --> properties --> Publish --> Application Files. In there you will find all the parts of your app. You might need to check the box "Show all Files" as it hides some things. Find what you need to be included and set it so using the little drop down next to it in the column "Publish Status".
The office interop required office to be installed on the machine.
You can use Open XML http://msdn.microsoft.com/en-us/library/hh180830(v=office.14).aspx or EPPlus http://epplus.codeplex.com/ to work with excel files without installing Microsoft Office.

C# Microsoft.Office.Interop

I need to reference this library, however when I right click and go to add references, I can't find it in the list.
I have office 2007 installed.
C# Microsoft.Office.Interop
You have to Install Office Primary Interop Assemblies first. You can download it from http://www.microsoft.com/en-us/download/details.aspx?id=18346

Exporting DataGridView data to Excel file in C#

I need to export data from DataGridView (in my WinForms application) to excel file. I googled some tutorials on the subject, but I'm having hard time getting any of the available solutions to work.
I started with this tutorial. But when I try to export datagridview to excel file i get Unhandled COMException in:
Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new
Microsoft.Office.Interop.Excel.ApplicationClass();
I've also tried this tutorial, but with the same result.
Another of the articles I've found and read was this one. Couldn't get code to work, probably because I can't find Microsoft Excel 12.0 object library in the COM tab of Add Reference dialog.
I'm using Visual Studio 2010 Ultimate.
If those libraries are not installed, you can download them from Microsoft:
For Specific office versions, see here:
Office 2003 Update: Redistributable Primary Interop Assemblies
2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies
Microsoft Office 2010: Primary Interop Assemblies Redistributable
Once you install the correct one, you should be able to find the library in the 'Add reference' section of the tutorials
One day I did what you need but I got it in VB.Net
So you just need to create a Class Library project and in that class
use my method so you can reference it through C#.
Take a look at this link (translate it to English):
http://foro.elhacker.net/net/aporte_exportar_datagridview_a_excel_pdf_y_html-t299075.0.html
and also you can download my example from here and re-use my method:
http://dl.dropbox.com/u/15208254/stackoverflow/ExportarData.rar
Regards.
You can use Excel Package Plus and export your data without a need for excel, or any other external dependancy

Creating add-in for Excel using C#

I want to use C# class methods in Excel. Can anybody guid me how to do it ?
The C# component will be excel add-in. How to create setup for this addin, so that I just need to give setup to user which will install add-in at client's machine. User should not need to do any other steps like registering the C# dll.
(Disclaimer: I develop the Excel-Dna library.)
You should have a look at Excel-Dna - http://excel-dna.net. The library allows managed assemblies written in C#, VB.NET or F# to expose high-performance user-defined functions (UDFs) and macros to Excel through the native .xll interface. The project is open-source and freely allows commercial use.
With Excel-Dna you can create a single .xll add-in file that the user can open as an add-in without any further installation or registration. Excel-Dna add-ins can expose RTD servers and customized Ribbons for Excel 2007 and Excel 2010 without additional registration, so you need no extra setup program.
You will need to create a new Visual Studio project of type Excel 2007 Add-In (or Excel 2003 Add-In). The option for this can be found (in Visual Studio 2008) at:
New Project dialog -> Project types -> Visual C# -> Office
This Add-In will need to be installed on the target machine(s).
The Add-In will be able to hook into the Excel object model and therefore access any loaded spreadsheets etc.
The Add-In will also be able to add buttons to the Excel toolbar/ribbon.
Try looking at VSTO, there's a section explicitly for Excel
You can create Excel projects within Visual Studio (previously known as Excel VSTO projects) or you can use a third party library such as ExcelDna.

Categories