What's the currently best way to extend Excel with C #?

I have professional versions VS2008 and VS2010.

I want to add a couple of buttons to a toolbar in Excel. When they are clicked, I would like to be able to open the form (either WinForms or WPF is fine) collect some values ​​from the user in the form, and then take that data + read the cell values ​​from the current sheet to perform some database operation.

What's the best way to do this with C #? I would really appreciate a pointer to any examples / tutorials. I understand that VS2010 has improved the process a lot, but I might have to deal with Excel 2003, which I don't think it supports.

I'm confused between Visual Studio 2008s Extensibility-> Shared Addin template and other Office Addin templates I've seen. I'm not sure if which type of solution is appropriate.

I'm new to Office development, so I am very grateful for any help to get me on the right track.

Many thanks.

+2


a source to share


3 answers


Several starting points:



Also, you want to learn .NET Excel Wrapper

The .NET Excel shell was born out of frustration with .NET and Excel. .NET Documentation. Interop.Excel is very small and the API bloated with difficulty to understand the parameters and methods that throw unknown errors.

What the .NET Excel Wrapper Should Do Make it harder to work with Excel in .NET and increase productivity, improve code readability, and reduce the amount of code you need to write.

+2


a source


The default approach to expanding an office using .Net is VSTO. VSTO supports Excel / Office 2003; if you chose an Office 2003 project in Visual Studio, it will support 2003 and up, but by supporting 2003, you will give up some of the features you can use if you target Office 2007 and up - like ribbon or custom taskbars. In addition to the links mentioned by KMan, I have a series of posts on my blog that provide a step-by-step guide for creating an Excel 2007 add-in with VSTO that you might find useful.



+1


a source


1: First, you need to get started with WCF to learn the basics of WCF. Getting started with WCF programming.

2: To extend excel with C #, you can use this third party excel library . It has many built in functionality to extend excel with your WCF application. This library has many built-in functions for loading, creating, modifying excel files. You can also easily create and manipulate rows and columns with built-in functions.

Below is a simple code to create an excel file in C #.

//First create a Workbook Manager object to load the file.
//WorkbookManager() is simply represent Workbook Manager
WorkbookManager manager = new WorkbookManager();
// Now load the excel file by calling Workbook manager object Workbook.Open() Method
//store Filename in filename variable
string filename = "D:/test.xls"
//manager.Workbook.Open() automatically create the file and open it to work.
Workbook workbook = manager.Workbooks.Open(Filename);
// Now you need to access your sheet by using IWorksheet interface method
IWorksheet sheet = workbook.Worksheets[0];
 //For create rows, you can call IRange
 IRange row = new IRange();
 //for create cell
 IRange cell = new IRange();
 foreach(row in sheet.Rows)
 foreach(cell in row.Cells){
     Console.Write(cell.Value.ToString())
 }
 // You can write here your further logic to whatever you want with rows and columns.

      

0


a source







All Articles