GridView Column click export data into Excel - c#

I'm new to the ASP.NET world and need some help.
I need to create a GridView which shows the Employee's name. When a user clicks on the Employee Name, it will call the stored procedure to get particular details from the database and export the data into an excel sheet.

There are commercial and open sources libraries available to facilitate this task, but I am a fan of DoddleReport as it is easy to configure and use.
I wrote a blog post demonstrating how to use DoddleReport and PetaPoco to export a SQL Server PIVOT query from an ASP.NET MVC3 application to Excel. The Excel portion of the task is only a couple lines of code.
The sample project is available on github

Related

Create online sheets using C#, SQLServer and AngularJS

I want to achieve the following -
1)Connect to SQL Server Database to get JSON data.
2)Use the JSON data to create spreadsheet like tables with multiple tabs.
3)The spreadsheet can be edited to have additional calculated features like math functions etc.
4)Create another tab depending on data present in the spreadsheet tabs
5)Publish this spreadsheet as a view only spreadsheet.
Is this possible? I am open to use any JS library.
I am looking for any excel like application which gives us the opportunity to create the spreadsheet with multiple tab + formulas and share/socialize it.
What is the best way/example to go about implementing this feature? I want it to work with AngularJS, JavaScript.
Like mentioned previously, the best solution for this would be to start with the Sheets API Quickstart for .NET here.
After you start getting a grasp on how the Sheets API works, you can easily connect to the SQL Server and retrieve the data you want in order to create a spreadsheet with your requirements.
You might find the following links useful:
spreadsheets.create - request to create a spreadsheet which will return the newly created spreadsheet
spreadsheets.values.batchUpdate - request to write multiple values in a spreadsheet
spreadsheets.values.append - request to append values to a spreadsheet
Reference
Sheets API Quickstart;
Google Sheets API Client Library for .NET.

Reading particular columns of Excel sheet

I need to read particular columns from an Excel sheet (say Columns A,P,Q,B) and also some particular cells (say C3 or D10). I do not need it to be displayed in a DataGrid view or anything (all examples I have seen use DataGrid).
How do I do that and write them into a new CSV file?
I have no sample code as I do not know how to proceed.
I sugest you use the ExcelReaderInterop library.
using Microsoft.Office.Interop.Excel;
Detailed example can be found here:
http://www.dotnetperls.com/excel
I had to deal with a similar issue a few weeks ago and could not find a simpler way to deal with this. The post suggest this overkill approach may be due to lots of legacy code in the library.
We have successfully used the Microsoft Access Database engine to open and read Excel files. The "2010 Access Redistributable" can also be installed on a server free of charge. What you asking for is a multi-step process:
Open a connection to the file using the Access OleDbConnection. In the connection string the "Data Source" is the file name.
Select the appropriate worksheet, which will return a DataTable object.
Grab a row from the data table or iterate over top of all of them myDataTable.Rows.
Access the column in question.
This post shows some of the process:
SSIS Excel Source Connection. What does it use to read Excel?
Hopefully this gets you pointed in the right direction.
I copied the columns that I needed to another excel sheet and saved it as CSV. Then read this csv to perform the task.
This was the easiest option as the machine I was suppose to run the program didn't have Microsoft office.

Dynamic Excel columns and rows to SQL

I have an Excel template which has dynamic rows and columns (it means the Excel template will be downloaded based on the parameters I select in my UI). Now there will be some data in the Excel sheet against those dynamic rows and columns coming from the database. I want to modify that Excel and import it so that only the updated(modified) cell values are updated in database. I thought a lot and I think this can be done with macros (by changing the color of cells with updated values and picking them up from C#). I would welcome any other thoughts/approaches for this.
An approach I have used is to create a webdav/REST service which can then be mounted as a drive in Windows.
The exposed file on the webdav service was simply a CSV, which users could edit in Excel, but the GET request was serviced by reading the database.
After making the changes, the user saved in Excel, which caused a PUT on the webdav service. The PUT request wrote the new values to the database.

Using SQL Bulk Copy to fill a database table

I'm working on an web app using ASP.NET MVC4. I have an Excel file with several columns (some of them are useless) and I'd like to export the data to a related table by uploading the file.
One of my superiors told me to use SQL Bulk Copy to do that. I search some information about that but nothing really interesting (for example, nothing about how to map the excel columns and the table fields).
Any idea/tutorial to do that?
Hello friend please review this article, i think it will contains all the required information you needed. but you need to do some modification as per your requirement.
SQLBulk insert from Excel
if you are facing any connection issue with your Excel workbook, please modified your excel connection string for that there is a good article provide all the necessary information regarding Excel connection string
Excel Connection String Sample

Pull info from Excel Spreadsheet into C# Web Application

I want to show information from an excel spreadsheet in a web page. The xls will have maybe 5 columns, and as many rows as needed. The columns will be 'Name', 'Created Date', 'Expired Date', 'Owner', and maybe down the road maybe more.
What I would like is for the C# to nightly read the xls, and display the information in a table on the website.
If there is a PDF available for download I am going to link that as well.
Thanks in advance,
Gene
Here is an article describing how to read an Excel file using the OLEDB data provider.
However, this probably needs to live in a service or its own executable and kicked off with a scheduled job to fill some tables that your web page looks at.

Categories