Click here to Skip to main content
11,492,523 members (61,702 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET .NET Excel VB.NET
I have implemented export dataset to excel using
:Excel template, which contains namerange where the data needs to be inserted
:FileStream and byte array

The problem m facing is, everytime i write data into excel, It also appends column header present in the datatable.
I want to avoid the column header, as this is already present in the excel template(row above nameranges)

Please provide me a solution.
Atleast let me know, how to get the content of HttpContext object in debug mode, so that i can do RnD with that.
Posted 10-Dec-12 18:48pm
Edited 10-Dec-12 20:37pm
Vinay iGATE at 11-Dec-12 22:25pm
I found out something in connection string as HDR.
Does anyone knows, whats the use of this?
HDR = YES / HDR = No
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Article: Fast Exporting from DataSet to Excel[^]
Similar answer: How to Export Value from Data Set to Excel Sheet[^]
Lot more similar stuff on CodeProject[^]

In short:

for (int col = 0; col < dataTable.Columns.Count; col++)
    for (int row = 0; row < dataTable.Rows.Count; row++)
        excelSheet.Cells[row + 1, col + 1] =

..and for bulk data you can go with:
excelSheet.get_Range("A1:H25", Type.Missing).Value2 =
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this I Hope it will solve your Issue

In .Aspx page
<asp:DataGrid ID="myGridView" Width="100%" runat="server" AutoGenerateColumns="False"
            DataKeyNames="Id" AlternatingRowStyle-CssClass="alt">
            <ItemStyle BackColor="#EBEBEB" />
            <AlternatingItemStyle BackColor="White" />
                <asp:TemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="ID">
                    <ItemTemplate >
                        <asp:Label ID="lblId" runat="server" Text='<%# Eval("ID")%>'></asp:Label>
                    <ItemStyle HorizontalAlign="Center" Width="15%" />
            <asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderText="Name">
                        <asp:Label ID="lblName" Text='<%# Eval("Name")%>' runat="server"></asp:Label>
                    <ItemStyle HorizontalAlign="Center" Width="20%" />
In .cs page
               myGridView.DataSource = dd.tables[0];

               public void ExportToExcel(System.Web.UI.Control ctl)
                 using (Control myCtl = ctl)
                HttpContext.Current.Response.AppendHeader("Content-Disposition", attachment);
                HttpContext.Current.Response.Charset = charSet;
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                HttpContext.Current.Response.ContentType = content;
                myCtl.Page.EnableViewState = false;
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
               //Renders the control here.

Keep smiling Smile | :) Smile | :) Smile | :) Happy codingSmile | :)
Vinay iGATE at 11-Dec-12 1:13am
I dont have datagridview. Data is coming directly from a table in a dataset :(
IpsitaMishra at 11-Dec-12 6:32am
you can add a grid and make that invisible just a suggestion :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 399
1 Maciej Los 266
2 KarstenK 210
3 CPallini 208
4 Sascha Lefèvre 195
0 Sergey Alexandrovich Kryukov 9,943
1 OriginalGriff 8,610
2 Sascha Lefèvre 3,609
3 Maciej Los 3,372
4 Richard Deeming 2,440

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100