.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

How to export from DatagridView to Excel Sheet in C# Windows Forms

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :Windows Application


I am developing an application that loads a spreasheet to a datagrid, i then add a column (with data) dynamically in the datagrid. How can I take the data in the whole datagrid and display it in a new spreadsheet. Please help!

View Complete Post

More Related Resource Links

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

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

In export, i want to disable column in excel sheet

Hello, I am doing Import/Export. While export i want to disable some column in excel sheet, so during upload or import same primary key I can use, instead of user modify such column. Regards, Sandeep    

Repeat header rows on all pages when you export to excel sheet and print it

Hello , I need to export report into excel sheet. And when people try to print it . The header rows only appear on First page of the print . Other subsequent pages d onot have header rows. I saw another thread saying SQL server 2008 R2 will solve the issue. Can you tell me that is fixed and how to i go about configuring it on SQL server 2008 R2.   Thanks Madhavi

Displaying formatting of an Excel sheet in a datagridview within a C# application


I've successfully used the Excel COM objects in C# to extract the contents of the sheets. I then use this information in a datagridview.

Rather than just cycle through each cell for the values to build up what needs to be displayed however I used the Worksheet.UsedRange.get_value() method instead which returns a 2D array of objects containing the string values of the cells.

I've done this since going through each cell individually appears to slow things down considerably, especially when larger Excel files are being opened. I would like to also apply as much of the formatting as possible from the file too, however there doesn't appear to be a clear way to extract formatting information in a similar way to get_value. I could go back to cycling through the cells, but this would probably incur an unacceptable loss in speed as a result.

Does anybody know how to retrieve formatting information using a way that's similar in terms of output to the way that get_value works?

Import and Export List data in excel sheet


Hi ,

I need to import based selective data from excel sheet and export data from sharepoint list, I'm new in Sharepoint.

can anybody guide me? What all possible ways are there and which would be the best.



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.

how to display sharepoint DocumentLibrary files details into datagridview of windows forms applicati



Now iam using sharepoint server 2007, here DocumentLibrary is having some files.

i need to display these files information into datagridview of windows forms application.

where datagridview columns are like

type        name (file name)   modified (date)        modifiedby     checked out to


i have the code like...




export datagridview to excel c#

 public static void Excel3(DataGridView dgv,string type)
      SaveFileDialog s_Lvl_Max =new SaveFileDialog(); 
      s_Lvl_Max.Filter = "xls files (*.xls)|*.xls|All files (*.*)|*.*"; 
      s_Lvl_Max.FilterIndex = 1;
      s_Lvl_Max.FileName = type+"_" + DateTime.Now.ToString("ddMMyyyy"); 
      s_Lvl_Max.OverwritePrompt = true; 

      if (s_Lvl_Max.ShowDialog() == DialogResult.OK) 
      Excel.Application oXL; 
      Excel._Workbook oWB;

        //Start Excel and get Application object. 
        oXL = new Excel.Application();
        oXL.Visible = false;
        oXL.DisplayAlerts = false;
        //Get a new workbook. 
        oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
        oSheet = (Excel._Worksheet)o

Export DataGridView to excel



I've rowte this code to export to excel but i get a "COMException was unhandled" Exception from HRESULT : 0x800A03EC

Hope somone can helpe!



private void linieBindingNavigatorSaveItem_Click(object sender, EventArgs e)


    //DataTable dt = new DataTable("Line");

    private void Form1_Load(object sender, EventArgs e)
      // TODO: This line of code loads data into the 'betaToolDataSet.Linie' table. You can move, or remove it, as needed.

    private void btnExport_Click(objec

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.

Application Architecture in Windows Forms 2.0

Applications have special support in Windows Forms. For starters, you can manage and tailor your application's lifetime, and, when the work flow is disrupted by an unhandled exception, you can choose from several methods of response. Then, there are several application models that you can employ, including Single Document Interface (SDI) and Multiple Document Interface (MDI) applications, each of which can support either multiple-instance or single-instance mode, the former the VS05 default and the latter requiring special consideration. All applications, however, can discover and use a wide variety of information about the system and environment they execute in.

Application Architecture in Windows Forms 2.0-Single-MDI Applications

Consider an MDI application like Microsoft Excel; files opened from the file system (by double-clicking) are all opened as separate child windows within the parent Excel window.7 For the first instance of an MDI application to open a new child window to display the file that was passed to the second instance of the application, the second instance must be able to communicate with the initial instance.

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.

Export SharePoint List to Excel Spreadsheet Programmatically using C#

In SharePoint applications, Custom Lists are used to store business data and Document Libraries to store the documents. But for data manupulation and analysis, Microsoft Excel provides very rich features as compared to SharePoint Lists. That's why people still loves to work on Microsoft Excel Sheets.

How to programmatically add controls to Windows forms at run time by using Visual C#

Create a Windows Forms Application
Start Visual Studio .NET or Visual Studio 2005 or a later version, and create a new Visual C# Windows Application project named WinControls. Form1 is added to the project by default.
Double-click Form1 to create and view the Form1_Load event procedure.
Add private instance variables to the Form1 class to work with common Windows controls. The Form1 class starts as follows:
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