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

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

Is there a way to export a datagrid to an Excel or html format file?

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :Windows Application
Hi all.. thanks for taking the time to help in advance!! :)

I've written a win application that has a datagrid which displays certain contents from a database, is there a way to allow the user to export the contents of that datagrid to maybe an excel file or html file so they can print it out themselves? I've done a lot of googling and most i could find were for web applications and not winform.. can someone point me in the right direction?

Thanks very much guys! :)

View Complete Post

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.

Export Dataset to excel sheet in a required format?



I know how to export a grid view to excel.

But here i have a Dataset which consists of data like below and also it need to display in a required format like below.

pno psubno pstate pdetailid pdetails

 12    1          CA         1           cbsdjcbdjc     

12     1          CA          2        cndcnjdcjcj

12     2           VA         4          xcndwkfcgygry

13     1            AL        1           ncdcnjdcndj

My excel sheet  should like this.

pid       pstate     

 12/1      CA             &nb

How to do wide search and export the records to excel file in ASP.net C# ?


This is my MYSQL  database connection :-

public static OdbcConnection Connection = new OdbcConnection("Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=jdmcrm; User=root;Password=admin;");

My table name is "customer" and  fields liek customerId , companyName , address and date ;

How to do wide search and export the records to excel file ? im quite new in asp.net .

Pls advise . Thanks





How do you freeze the tablix header row in an Excel export file in SSRS 2008?

So this is totally killing me. I've found out how to make a tablix header row repeat on each page of a PDF export file in SSRS 2008 (which I won't even get started on because all I can say is that 2005 is way better), but I cannot figure out how to make a simple header row of a tablix freeze in an Excel export file.  The tablix is right at the top of the body and spans the entire width of the design area.  How in the world do you get it to freeze in the Excel export file?

ASP.NET-Gridview - Export to excel- column format

Hi All, I am exporting gridview data into excel sheet. I have a column  which is a code for which data is like 012,013 etc. But when this data is being exported , in the excel sheet I can see the data as 12,13,14. but actually it should be 012.... Is there any way to specify the format of such columns in my datatable so that they are in the same manner as in the database? Please provide some information on this.Thanks in advance.

SharePoint 2010 Export list Items to Excel, wrong url in iqy file

Hi, I have a SharePoint 2010 Environment that uses https://portal.<something>.com. Exporting to Excel of a list uses wrong URL. When I go to the a list, select the list to show the "office ribbon" and then select export to excel, excel will show the error "Excel cannot connect to the SharePoint List". When I take a look at the IQY file that is created it contains the wrong url: http://portal.<something>.com instead of https://portal.<something>.com Changing the URL in the IQY file manualy to https://portal.<something>.com and then opening it will excel is working fine, list data is exported to excel then. Alternate access mapping is configured to use https://portal.<something>.com as default, export to access is working normaly. I already deleted the http://portal.<something>.com alternate access mapping once to see if this fixes the problem. No fix, even not after IISreset or rebooting the server. Where or how is the export to Excel IQY file created and where is it possible to fix the URL it is putting in the IQY file? Grtz, Arjan

Export datagrid to Excel without Excel component



We have the requirement to export the data from the grid excel. We can't install the Excel on the server. The excel generated need to be in the printable format. The excel generated needs to have custom headers, footers, repeatble rows, columns and landscape / portrait orientation style.


Please suggest how this can be achieved.

Data Export to Excel file using "Response.ContentType = "application/csv"


I have developed code to export data to Excel using Response.ContentType = "application/csv". The output Data Excel file loaded with 65536 Rows only, this file is not loaded completely since the limitation of excel is 65536. My Recordcount is more than 700000.

Please any one let me know how I can Export Data to Excel file over than 65536 Rows.

Email: thamaraiselvann@ayso.org

can I use SQL Server to export an excel file directly?


I just want to know except use owc

can we use SQL Server to export excel file ?

if it can be , how to do? thanks alot

Difference in Excel Format Display in Different Machines when i export from ssrs2008R2


i develop one report  and i am using ssrs2008R2

  • when i exporting into excel sheet its dispaly perferct in my mechine (means printview shows perferct with looose any column )
  • when my tester exporting into excel sheet its dispaly different meas missing last coloums in report  

Both are using WINDOWS7 Enterprice ,office2007 ,ssrs2008R2  

Please note that the reports gets generated in my machine, say System A, as expected. But as I figured out that in some machines, say System B,  the reports generated are having alignment problems.
I had compared the System A and System B machines in the following parameters :
1) System Resolution - 1024x768 (Same)
2) Microsoft Office Excel Versions - 2007 (Same)
3) Remote Desktop Login into System B from System A -- Reports are properly displayed
    Remote Desktop Login into System A from System B -- Reports are not properly displayed

can Plz help me as possible as earliy

my mail address :praveen6867@gmail.com

When i export a MS Excel file generated By SSRS 2008 i'm not able to change the sheet name (Sheet 1

When i export a MS Excel file generated By SSRS 2008 i'm not able to change the sheet name (Sheet 1,Sheet 2,Sheet 3) dynamically.So Please try to give me a solution.

When i export a MS Excel file generated By SSRS 2008 i'm not able to change the sheet name (Sheet 1



When i export a MS Excel file generated By SSRS 2008 i'm not able to change the sheet name (Sheet 1,Sheet 2,Sheet 3) dyanamically.Sp Please try to give me a solution.

Export to Excel gives error before opening file


I have a web page with a gridview control and a button for Exporting to Excel

I get following error when exporting to Excel.

"The fiel you are trying to open, 'someFileName[1].xls, is in a different format than specified by the file extension. Verify that file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

Clicking Yes opens the file. I would like to avoid showing the above error to the users.

Following code is used from the click event. I've left the commented code here to show what I've tried based on results from internet search. I have Microsoft Office Excel 2007 on local PC.

public static void ToExcel(DataTable dt, string fileName)
			string attachment = "attachment; filename=" + fileName + ".xls";

			GridView gvExcel = new System.Web.UI.WebControls.GridView();
			gvExcel.AutoGenerateColumns = true;
			gvExcel.DataSource = dt;

			//HttpContext.Current.Response.AddHeader("content-disposition", attachment);
			//HttpContext.Current.Response.ContentType = "application/ms-excel";
			HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

Export html table to excel directly by using javascript


hi all brothers,

           I have a question here, I trying to export the html table  to excel by using javascript and I managed to get the sample  ( source code as below).The sample below will automatically export all the records in html table into excel directly. The question is , what if I  want to generate the excel in client pc with a save file prompt dialog box that indicate the location to save without opening the excel sheet in the client pc. 


function write_to_excel()

var mytable = document.getElementsByTagName("table")[0];
var rowCount = mytable.rows.length;
var colCount = mytable.getElementsByTagName("tr")[0].getElementsByTagName("td").length; 

var ExcelApp = new ActiveXObject("Excel.Application");
var ExcelSheet = new ActiveXObject("Excel.Sheet");
ExcelSheet.Application.Visible = false;

 for(var i=0; i<rowCount; i++)
  for(var j=0; j<colCount; j++)
   str= mytable.getElementsByTagName("tr")[i].getElementsByTagName("td")[j].innerHTML;

Export to a .tpf file (textwizard predefined format)


A tpf file is a "textwizard predefined format" which is a metadata description file from SPSS (the application SPSS).

The tpf file describes the columns and datatypes of the .dat file.

The SPSS site mentions it is a binary file, therefore I was curious whether someone has made a component which is able to generate a .tpf file on a given metadata inpit (so to say my query would deliver the datatypes, lenghts and so on, the component produces the accompanying .tpf file)

Business Intelligence professional

Problem in Date Format While Exporting To Excel Destination From Flat File Source In SSIS



I have a flat file(.csv) which contains data(strings incuding date in yyyy-mm-dd format).This i am using in Flat File Source and want to export those data to an Excel Destination.Before exporting to Excel Destination i have created a Derived Column component where i am using an express to get day,month,year part and creating a date sting in dd/mm/yyyy format then conveting it to DT_DATE datatype and then exporting to Excel Component.But while exporting to Excel this date format is getting changed to mm/dd/yyyy format.

The expression i used in derived column is

(DT_DATE)(SUBSTRING(date,9,2) + "/" + SUBSTRING(date,6,2) + "/" + SUBSTRING(date,1,4))

where date is a column from Flat File Source.

Even I changed the Locale to English(United Kingdom) in Flat File Connection Manager for the above .csv file.But still it didnt work.

I searched a lot in google and failed to get any solution on this.

Can anyone help me in solving this issue ?

Export Visio Database Table Names to Excel

If you use the Enterprise Architect edition of Microsoft Visio for data modeling regularly, then there is a good chance that at some point you've wanted to export just the table names into Excel. You might want to do this to map logical ERD entities to physical data model tables, track project status by entity, or track overlap between database versions.
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