0

I have been struggling the last few hours trying to get an excel spreadsheet/workbook to be displayed on a Windows form using Visual Studio 2012, C#. I can retrieve the data from the workbook and display it on the form, but I need the functionality of Excel in the application, including stuff like Filtering, Conditional Formatting, Formulas, etc.

I have read up quite a lot, and as I understand it, there are no controls in Visual Studio to embed these (Office) files due to licencing, which makes sense. I have found a solution though, to display the file in a WebControl (I am sure I will be able to work with this), but when I try to load the excel file in the web control, it prompts the user to either open or save the file, and when 'Open File' is chosen, the file is opened using Microsoft Excel.

As I understand it, this happens because the ContentType (Mime type, Excel ContentType) of the file needs to be set in the browser (I need to do more research on this as I am not yet familiar with this concept, ).

The resources I am using:

The latter is almost exactly what I want to achieve, but keeps on asking to save or open the file, rather than just displaying it in the WebControl

Any help on this matter would be greatly appreciated.

Community
  • 1
  • 1
Johan Aspeling
  • 765
  • 1
  • 13
  • 38
  • *`there are no controls in Visual Studio to embed these (Office) files due to licencing, which makes sense.`* Have you ever heard of VSTO? –  Apr 23 '14 at 10:32
  • Not sure this is much of help for you here but [**check this out**](http://stackoverflow.com/questions/17406319/display-a-part-of-an-excel-sheet-on-a-userform-using-vba/17407415#17407415).. Afaik, you can just embed the entire Excel application into winforms. You can have the basic functionality with 3rd party libraries but that's it.. it does not work like running "Wine" on linux :P Your client needs to have an Excel on his machine and you can communicate with it using Com Interop ( or EPPlus, OpenXML, ClosedXML etc )... Or go for VSTO –  Apr 23 '14 at 10:38
  • Thanks for the help - I looked into VSTO, Net Office and OWC (Office Web Controls), and the only package I could find that allows me to actully place an excel control on the form is OWC11, but it seems so buggy, and I cant find any examples illustrating how to use the control in C#, much of the given code is in VB. EPPlus gives great functionality to save to excel, I havent yet looked at OpenXML, but I am highly considering only using a datagrid as this is starting to look like a dead end. – Johan Aspeling Apr 24 '14 at 06:48

2 Answers2

1

There're commercial WinForms libraries from DevExpress, Syncfusion and Infragistics. I'm using DevExpress. I'd suggest their WinForms Spreadsheet control inspired by Excel. They also have Spreadsheet File API for .NET and Spreadsheet UI controls for ASP.NET, MVC, WPF, ASP.NET Core and Bootstrap.

You can try their free 30-day trial and see if DevExpress UI controls suit your needs.

Max
  • 47
  • 2
-2

Use DataGridView and program a functionnality if it doesn't have it! OR Use Excel COM to create an instance of Excel.

Yan Veilleux
  • 143
  • 1
  • 12
  • I am considering a Datagrid as a workaround, as I mainly only need the filter option. IT would be ideal to have an instance of excel to have all of its functionality, but its taking way too long to get the excel stuff ([VSTO](http://www.microsoft.com/en-za/download/details.aspx?id=23656 "VSTO"), [Net Office](http://netoffice.codeplex.com/releases/view/70943 "Net Office"), [Office Web Components](http://www.microsoft.com/en-us/download/details.aspx?id=22276 "Office Web Components")) to actually work.. – Johan Aspeling Apr 24 '14 at 06:42