Display Excel Spreadsheet in WinForms, C# - c#

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:
Logic to save the contents to an Excel File: EPPlus
I was working from the following project, among others: Winforms Excel Example
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.

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.

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

Related

C# open and edit excel file inside windows forms

What I've done:
I am trying to be able to open an excel file in a windows form so that I can create a disposable pivot table. I have tried a few options that I've found on Google but I've run into a brick wall.
One option that I found was to open in wpf user control document viewer, while I can open the file I cannot edit it.
I have not figured out a way to edit the excel file.
My Question: I need to display a blank excel sheet inside a windows form, then I will need to add a pivot table to the sheet that is embedded inside the windows form where when the form closes it disregards the sheet that was open in the form. What is the best way to do this?
For all tasks related to programmatic construction or manipulation of Office documents, the Open XML SDK is the proper solution. All other APIs are either limited in scope (other 3rd-party Excel writer APIs support only a subset of the features of Excel documents) or have issues being used programmatically (Office automation is notoriously error-prone and should NEVER be used in a server environment). The Open XML SDK allows you to directly create and manipulate the data structure that is the Office document. It does not require Office to be installed. Additionally, the Open XML Productivity tool (also available via the download link below) will allow you to open an existing document and see EXACTLY the code required to construct EXACTLY that document. Very useful!
Download: https://www.microsoft.com/en-us/download/details.aspx?id=30425

How to generate excel like report in WPF?

I have this Excel Sheet That I want to generate from my WPF Application, What is the easiest way to do so, bear in mind that the table in the sheet may have many containers and each container may have one or more sizes and so on as shown.
I'v looked at the ReportViewer provided in WPF but I don't know how to design such a report using the ReportViewer.
Another thing came to my mind is to fill the excel sheet from the WPF and I found a way to do so by specifying tags (Ex: Date: ) in which I can fill these tags from my WPF application, but I don't know who to generate tables and set their columns and rows according to the data in the database.
Thank you.
Did you try adding Microsoft.Office.Interop.Excel as a dll, and try the code given here.
Or have a look at this sample:
WPF Spreadsheet
I have made good experience with the EPPlus library. The nice thing is, you don't need any MS Office components on your OS to generate the excel files.

export to excel from sharepoint - complex

There is some code/werbparts on our site that display a lot of data in a grid on our site. In addition, they have another page with a few charts.
I need a way to create functionality to export this to excel so the user can click a button and save everything.
The chart will actually have to be built in excel, I can't just grab the picture from the website and display it.
Also, the data from the grid will have to be put into a spreadhseet. I am not as worried about this part.
I have exported to excel before, but it was just basically printing some data which was tab delimited with a certain doc type .
This actually will need to use different work sheets and use some excel functionality.
(I need a better answer than use excel services)
Thanks!
Use Epplus is a third party library for creating and manipulating excel files(xlsx)
Dunno about sharepoint, but the OpenXML SDK might be what you're after:-
http://msdn.microsoft.com/en-us/library/bb448854.aspx

import c# winforms into excel,

Please show me the code how to import winforms controls, into excel xls. file.
I have created one winform in c#, but while taking print out c#,
there s no table border lines, because in c# winforms onle table layout tools s present, so i need to import this to excel and convert to table format and take print out.
thank u.... i expect the answer from your side...
I honestly don't really know what you're asking, but I'm going to take a guess that you want to host WinForms controls in an Excel workbook?
If so, you may find these MSDN articles useful:
How to: Add Windows Forms Controls to Office Documents
Using Windows Forms Controls on Excel Worksheets
Otherwise, you'll need to clarify your question and ask something a little more specific.

C# Best way to read a XLS (XLSX) file and populate a datagrid

What is the best (free or paid for) to read Excel files (XLS and XLSX) using C# and populate a datagrid, I would also like to have any changes made in the datagrid be written back to the file.
I should also add that it needs to be high performing as the datagrid can contain a significant number of rows (10,000+).
This would be used for a commercial application so it would need to be distributable.
This is a Windows Forms application.
I recommend databinding the datagrid to a dataset/datatable populated via the ADO.NET OleDb provider.
You'll find an example at Read from Excel using OleDb in a Windows Service?
I also found How To Use ADO with Excel Data from Visual Basic or VBA and How To Use ADOX with Excel Data from Visual Basic or VBA to be useful in knowing how to create a table (sheet) and access sheets and ranges.
It works very well for xls files. I haven't tried using it for xlsx.
SmartXLS for .Net
It support read/write xls/xlsx files and can import/export workbook datas to/from a datagrid.
You don't define whether you speak about web or fat client application.
You can use Open XML SDK 2.0 for Microsoft Office for reading XLSX file. (see http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&displaylang=en and http://msdn.microsoft.com/en-us/library/cc850837(v=office.14).aspx for some examples and also on http://openxmldeveloper.org/default.aspx.)
You can display and allow to modify the content in a grid like jqGrid (see http://www.trirand.com/blog/?page_id=6) if you use a Web application. This grid is the best jQuery plugin which has a lot of different features and allow implement practical every scenario.
After all you can use Open XML SDK to save result in a modified XLSX file.
For xlsx :
http://msdn.microsoft.com/en-us/library/bb332058%28v=office.12%29.aspx
http://www.codeproject.com/KB/office/OpenXML.aspx

Categories

Resources