EPPlus: Creating Sort Columns - c#

I am trying to create an excel spreadsheet like so in EPPlus:
My main trouble stem from getting the drop down to appear. I understand this can be easily done in desktop Excel by selecting the Data -> Filter tool.
Is there any way to achieve this result using EPPlus? (Or any other built in .NET method)

I achived this result using the following line of code:
ws.Cells[$"A{row}:S{row}"].AutoFilter = true;

Related

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.

Show Excel workbook without save in C#

I am creating an Excel file in an WinForm app (VS2008) in runtime. I am exporting some data into it from datagridview. After export, i would like to show this file in excel, but dont want to save anywhere. My goal is to use it as an alternative of creating many reports in crystal. Is it possible ?
If you are using Interop Service, you only can make workbook application visible equals to true.
[workbookobject].Application.Visible = true;

Select/Insert/Update/Delete Excel 2007 File and C#

I am using DataGridView and i am binding my Excel file to DataGridView.
I am able to read from the Excel file as well as insert to that file using DataGridView. But I am not able to delete and update that file.
It's giving an error that says:
Deleting data in a linked table is not supported by this ISAM.
Is there any other method to perform these operation in an Excel file using DataGridView. Or simply how can I delete and update a record in an Excel file using DataGridView in C#.
I am afraid that a normal delete (like from access for example) is not supported as mentioned here by microsoft, i think you should consider using MS Access as your data source since it is much easier to deal with or you have to work around a different approach like deleting the while file and recreating it each time for both deleting and updating (not recommended).
In the page I linked they said the best way is to empty the cells for the row u need to delete.
good Luck

Export Datagridview records to Excel

Hey friends i need to export records of datagridview of winform to MSExcel. I want to do it without using any DLL i.e., with the buid in properties of C#. So is there any good solution for my problem?
Export the data as CSV file. Excel can read those fine.
A common way to do this would be through MSOffice PIAs. Is that what you'd like to avoid?
You can read the values from data grid using reflection or you can take your data model which is bound to the data grid and create a csv file. The csv file can be read by MS Excel.
I followed this video tutorial, in 10min you can do it, you must use the System.Data.SqlClient reference, make a method, and override, the code for the button, and put the gridview in a form tag, here is the link export from datagridview to excel

Programmatically generating Excel workbook with pivots and charts

I need to create a workbook which has a raw data on a sheet and a pivot table on another sheet. The pivot is created from the raw data. Then I need to create a chart with this pivot on the same or new sheet.
How can I do this in C# - and is this possible using VSTO?
Easiest way to do it?
Use Open XML SDK 2.0
Build a pre-generated version of the workbook with raw data, pivottable and pivotchart already created.
Install the OpenXML SDK 2.0 setup package
Use the OpenXML SDK 2.0 productivity tool from this install to open the workbook
Select the root element on the left hand pane, and then right click and select Reflect Code
Done - on the left pane is a complete C# class with the necessary code to generate the file.
Well not quite done as you still need to refactor the code to take into account dynamically adding the required data content, however this will get you 97% of the way if you already know C# fairly well.
I've done something similar to this before, but I didn't do it using C#. I used VBA since the language is already built in to Excel.
My approach was this:
Create a worksheet called "RAW DATA." This worksheet has a QueryTable object in it that can be updated via code in VBA.
I manually created a pivot table based on the QueryTable in the RAW DATA worksheet.
I then added code in VBA so that after RAW DATA was updated, Pivot Table was refreshed with the new data.
This method works really well if the layout of your raw data and your pivot table stays the same. I have a workbook that I made for a cowork that updates multiple sheets with pivot tables based on one set of data. She really likes it because just by clicking one button, she has a refreshed view of all of her data.
If this approach works for you and you'd like more details as to how to implement some of those methods, let me know more details of your situation and I can try to help you out.
One option is to connect to database from Excel and refresh the "Raw data" sheet, via VBA or defining an SQL query in Pivot data source. This is not so great as the user who opens the file must be able to connect to the database.
The other option is to fill the "Raw data" sheet programatically via C#. There are numerous libraries that can help you with that, even some free ones, but you can also do it yourself by using the Excel XML format (SpreadsheetML). You can use the Excel 2003 XML format or the new Open XML Excel format. The latter is far more complicated, but with it you can also take advantage of the OpenXML SDK and the Excel Package API.

Categories

Resources