.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Exporting Data From Data Grid to Excel Or World

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :ASP.Net


i am facing the problem in the exporting the data from the datagrid to excel, I have master page concept in the project where as i am trying to create the export function in the child contrl.

on the button click i wrote the below code

            Response.AddHeader("Content-Disposition", "Attachment; FileName = FileName.xls");
            Response.Charset = "";
            Response.ContentType = "Application/vnd.xls";

More Related Resource Links

Unable to export data to an excel file in grid format!!!

I'm exporting data to an excel sheet from the ojects list. The data is exporting to excel sheet well, but I'm unable to see the grid format for the data. The data is looking with out the rows and columns lines. I think I'm missing to set some property or somethnig ehwn exporting.   Any help would be really appriciated.

Excel External Table Data can only create new SharePoint List when Exporting from Excel?

I have a SQL Query that I refresh everyday in Excel. I want to be able to export this list over to a SharePoint list right after my refresh in Excel but I can only Export to a SharePoint list only once. If I try to export again to the same list then it will give me the error "The specified list name is already in use on this server. You must rename the list before publishing it to the server." I have web parts that have connections to this list and I do not want to export my Query to a new SharePoint list everyday. Does anyone know a way around this issue?

Output data grid as excel

Hi,I'm trying to output a data grid as excel when someone clicks a button on a web page.I have the data grid working and have found some code to do the excel output, but can't quite get it working.  The code is like this:using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections.Generic; using System.Linq; using System.IO; using System.Web; using System.Web.UI; using umbraco; namespace MyDataExport { public partial class ExportData : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); } } private void BindGrid() { SqlDataReader reader; SqlConnection conn = new SqlConnection(GlobalSettings.DbDSN); SqlCommand comm = new SqlCommand("SELECT * FROM budgetData;", conn); try { conn.Open(); reader = comm.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); reader.Close(); } finally { conn.Close(); } } private void btnExportToExcel_Click(object sender,System.EventArgs e) { ExportToExcel("Report.xls", DataGrid1); //This line is erroring, saying 'DataGrid1 does not exist in the current context' } private void ExportToExcel(string strFileName, DataGrid dg) //This line errors, saying 'The type or namespace name DataGrid c

Exporting Data from SQL Server to Excel; From Excel to SQL Server

I read some documentation on the web today about exporting data from SQL Server to Excel, and doing the reverse, exporting data from Excel to SQL Server.  Actually, this link was pretty good:



For one thing, what is Excel linked server "EXCELLINK"?


This is pretty good too:



This is very good; gets pretty complicated though:




I’m still pretty confused about how it all works.  It’s very easy to turn on the Macro Recorder in Excel, connect to SQL Server, choose a Table, and import date from that Table, but I would like to know if there is a more eloquent way of retrieving data, rather than doing something like:

"ODBC;DRIVER=SQL Server;SERVER=EXCEL-4J2W8KYNP\SQLEXPRESS;UID=;APP=2007 Microsoft Office system;WSID=EXCEL-4J2W8KYNP;Trusted_Connecti" _

Data shows #value! after exporting to excel



I am using SSRS 2008. I am trying to export the report to excel format. In the Preview option, I am able to see the exact number, but after exporting the data to excel, data is showed as "#value!"

How to solve this?

Thank you

display data into GridView from excel sheet

I have to display data from excel sheet into my gridview and also I need to figure out a way to store data into excel files from my web page. I am using C# 3.5, VS 2008.

Creating an Excel Spreadsheet and Adding Data to It Programmatically

The Interoperability services make it veryeasy to work with COM Capable Applications such as Word and Excel. Thisarticle reveals using Excel from a managed application. Excel is thespreadsheet component of Microsoft Office 2000. The majority of Excelprogrammatic functionality is exposed through Automation via the typelibrary Excel9.olb. The intention of this article is to express that amanaged application can interrelate with Excel as a COM server.

delete data in excel sheet



           I have write the code for deleting the data in excel sheet. but we have got the error" Deleting data in a linked table is not supported by this ISAM."

     below I paste some code snippest.

string strDelete = "Delete  from [" + strSheetName + "$]";

            cmdExcel.Connection = con;
            cmdExcel.CommandType = CommandType.Text;
            cmdExcel.CommandText = strDelete;


Please can anybody this answer.It is urgent

Export Gridview data to Excel sheet


Hi ,

     I have a requirement where i need to export the gridview data to excel.My code export the data in excel that was fine.

But the enchancement needed now , I was exporting the 3 gridview in same excel sheet under the workbook.

Now i need to export the 3 grid view in 3 different sheet in the same workbook.

so can please tell or share the updated code in my below code ...

public void writeovrsummary()


        Response.Write("Overall Summary");
        //Response.Write("Report as of " + DateTime.Now.ToString("hh:mm ss tt"));

        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        SqlCommand com = MyConnection.CreateCommand();
        com.CommandText = "useroverall_Report";
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new

Insert data to Excel using OLEDB



I am trying to insert data to Excel Document using OLEDB as follows:-

 sql = "Insert into [MyFirstSheet$] (" + Title1 + "," +Title2 + "," + Title3 + ") 
values('" + Value1 + "','" + Value2 + "','" + Value2 + "')";
myCommand.CommandText = sql;

 sql = "Insert into [MyFirstSheet$] (" + Title1 + "," +Title2 + "," + Title3 + ") 

values('" + Value1 + "','" + Value2 + "','" + Value2 + "')";

myCommand.CommandText = sql;


But, the Title1 ,Title2, Title3 are in the 3rd row of the Excel Document. So, the data is not inserted.

Merge SQL to Excel--Need .Net button to open on fly and have current SQL data!


           Hello all,
I do not know if this is the proper place to ask this, but my question is...
I have a SQL DB and I want to convert it to Excel Sheet (I did this using the wizard)!
In my aspx page I have a button.  So when I press this button I want the Excel sheet to open!  But I need the Excel sheet to show me the up to date information that is in the SQL DB.  

Passing Data to a Cell in Excel



I have a webpage that is created in Visual Studio 2008 and programmed in C#.

I have a web form that prompts the user to enter a value into a text box.  For now, I do not have any validation on that field (I will be adding that later).

I need to pass the value that the user has entered to cell C1 of the excel spreadsheet (user_info.xls).

I understand that using excel is not ideal, but unforutnately need to try to make this work with the excel spreadsheet.

I do not have any code for this yet, because I honestly do not know how to begin.

The action of poulating the excel spreadsheet will be intialized from the On Click event of a Submit button.

Any suggestions would be much appreciated.

Thank you in advance for your assistance,


display data in excel 2007


 I am using .net  version 1.1  and  excel 2003 to display data.I need to display data in 2007 .Can  anyone suggest the reference to be added ,connection string change and what should be imported.  

Data 2.0: Expose And Consume Data in A Web Services World


The goal of the ADO.NET Data Services Framework is to create a simple REST-based framework for exposing and consuming data-centric services easily.

Elisa Flasko and Mike Flasko

MSDN Magazine August 2008

Test Run: Using Excel For Test Data


This month see how to use Excel for test automation storage, whether you're just starting out with NET, or you're an advanced programmer.

Dr. James McCaffrey

MSDN Magazine November 2006

Excel: Integrate Far-Flung Data into Your Spreadsheets with the Help of Web Services


Excel 2003 lets you dynamically integrate the data provided by different Web services. It also lets you take advantage of the latest capabilities in Office 2003 to customize list views, graphs, and charts, and to catalog bulk items online or offline. Find out how you can makle the most of the data returned from your Web services with the Office 2003 Web Services Toolkit API.

Alok Mehta

MSDN Magazine February 2005

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend