opening sheet and selecting cells excel/c# - c#

Hello I am looking for a way to open an Excel sheet programmatically and allow the user to be able to select a range of cells. My reasoning behind this is I am currently developing a lot of individual excel upload forms for pulling data in to a database I would like the ability to select the column headers as simply as highlighting the cells through excel and presenting a textbox for each to enter the equivalent DB table column name and store these. So effectively a form to create a form.
Many thanks
Charlie

Please check this article: Opening and Navigating Excel with C#.
There is also a section in MSDN library that completely covers Excel PIA.

Related

Embed office 2010 excel file in a c# Winform Application

I have spent the last 2 hours researching how to embed an excel file along with its formulas for a few cells and display it in a Winform application so the user can enter values and also the c#app can modify cell values based on some other resource data that is fed in via a USB port.
I cannot find any method other than these two - the first isn't supported and the other is 16 years old. Is this possible / supported to embed an excel sheet in a c# application?
Please note, I do not want to open the excel sheet and copy the data into a datagrid or similar as i need to use excel's functionality of conditional formulas to turn cells green if certain criteria are met etc etc the list of excel benefits goes on here. There are hundreds of these conditional formatting and embedded upper/lower limits in an existing excel file and i just want to embed the file and use excel's already excellent functionality.
Method 1 DSOFramer - No longer supported
Method 2 https://www.codeproject.com/Articles/15760/How-to-Integrate-Excel-in-a-Windows-Form-Applicati
using interop.excel with c# you can open excel, show it, interact with it using events to capture cell entry and cell change. its not embedded in the form but the end result is the same.

How can I create an Excel sheet view for user input in C#?

I wanted to create a view that is the same as an Excel sheet of some rows and some columns in which user can give inputs and it should grow dynamically but some cell should be filled by program internally and should be read only. I am making an windows form application using C#. Is there any way to do it in C#?
There are several tools to aid you in doing this task. Telerik and Infragistics are 2 of them.
http://www.telerik.com/
http://blogs.telerik.com/aspnet-ajax/posts/13-07-30/create-excel-asp-net-grid
http://www.infragistics.com/products/windows-forms/infragistics-excel/
This article may be useful too.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;304662

Displaying Tables from a document in a WPF application

I am working on a small application which reads through the word document and analyze it. The data present in the document are present in the form of tables ,Is there any way to display the data(tabular data) in the application..?
If DGV is the only solution for displaying a table ,Is there any way to bind the Interop table to Datagrid
I don't know if this would be the best approach but this is what I came up with right now. Google shows that there are many solutions to bind Excel to a DataGridView but hardly any for Word. In fact Stack Overflow also has many answers on converting Word to Excel.
Therefore, why not convert the Word contents to Excel and then bind the Excel contents to DGV? It's a roundabout way I know, but something is better than nothing. Here are some links that may help in this regard:
Programatically converting from MS word to Excel
Display excel file content in a Datagridview
http://www.dotneter.com/reading-excel-and-binding-to-datagridview-using-microsoft-office-interop-excel
Transferring data from Excel to dataGridView
If its just a matter of displaying then directly display the Word document in you WPF application.
Here, the link to achieve this.

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

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