How to embed Excel in a .NET WinForms App

  1. Download and install owc11.
  2. Run AxImp on OWC11.dll, which will have been installed in the microsoft shared\web components directory (ie C:\Program Files\Common Files\microsoft shared\Web Components\11\).  AxImp.exe can be found in the Windows SDK (ie, C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\AxImp.exe).
  3. In Visual Studio project, drag OWC11.dll to a toolbox tab and drop the Excel component on form.

Voila.  When it comes deployment time, you’ll need the AxInterop.OWC11.dll.

Some sample code:

Set a specific cell value:
Spreadsheet1.Cells.get_Item(row, col).set_Value(System.Reflection.Missing.Value, "BSXBW2183NN");

Get the string value of a specific cell:
Spreadsheet1.Cells.get_Item(row, col).get_Value(System.Reflection.Missing.Value).ToString()
or
Spreadsheet1.Cells.get_Item(i, 1).Text.ToString();

Set the background color of a row:
Object ob = "#66FF66";
Spreadsheet1.Rows.get_Item(row, System.Reflection.Missing.Value).Font.set_Color(ref ob);

Technorati Tags: ,

Print | posted on Thursday, September 17, 2009 9:19 AM

Feedback

# re: How to embed Excel in a .NET WinForms App

Left by M$ got me again at 10/29/2010 9:34 PM
Gravatar c:\Program Files\Microsoft Visual Studio 9.0\VC>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AxImp.exe" "C:\Program Files\Microso
ft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Owc11.dll"
AxImp Error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))

Your comment:





 
 

Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski