Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2007, 07:01 PM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Export Gridview to Excel and Hide column

Hi,

I have a gridview in my asp.net 2.0 vb application and I export the whole table to Excel using a button. The first column of the gridview is an edit column. When I export it, it just shows up as text in the excel file. How do I remove this column so it doesn't get exported to Excel?

Thanks!

 
Old November 3rd, 2011, 04:58 AM
Registered User
 
Join Date: Nov 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
you can easily export DataGrid to Excel in your Excel ASP.NET application with this Excel C# component.

Here is a sample code (to change what columns to export just use another overload of InsertDataTable method):
Code:
DataTable people = (DataTable)Session["people"];
 
// Create excel file.
ExcelFile ef = new ExcelFile();
ExcelWorksheet ws = ef.Worksheets.Add("DataSheet");
ws.InsertDataTable(people, "A1", true);
 
Response.Clear();
 
// Stream file to browser, in required type.
switch (this.RadioButtonList1.SelectedValue)
{
    case "XLS":
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", "attachment; filename=" +
             "Report.xls");
        ef.SaveXls(Response.OutputStream);
        break;
 
    case "XLSX":
        Response.ContentType = "application/vnd.openxmlformats";
        Response.AddHeader("Content-Disposition", "attachment; filename=" +
             "Report.xlsx");
        // With XLSX it is a bit more complicated as MS Packaging API
        // can't write directly to Response.OutputStream.
        // Therefore we use temporary MemoryStream.
        MemoryStream ms = new MemoryStream();
        ef.SaveXlsx(ms)
        ms.WriteTo(Response.OutputStream);
        break;
}
Response.End();
 
Old March 1st, 2012, 02:16 AM
Registered User
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help me out Plx

i am new user.. i have no programming background kindly help me out what should i do





Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Hide column and retrieve value snufse ASP.NET 2.0 Basics 1 July 24th, 2008 03:22 PM
Export ALL records from GridView into Excel or CSV kevorkian ASP.NET 2.0 Basics 7 June 17th, 2008 01:28 PM
Export GridView data to Excel file rao965 ASP.NET 2.0 Professional 0 June 14th, 2007 10:18 AM
Adding to Export Of GridView to Excel rsearing ASP.NET 2.0 Professional 17 January 25th, 2007 02:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.