Click here to Skip to main content
Rate this: bad
good
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
:Httpcontext
: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 17:48pm
Edited 10-Dec-12 19:37pm
v2
Comments
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
good
Please Sign up or sign in to vote.

Solution 2

Refer:
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] =
                dataTable.Rows[row].ItemArray[col];
    }
}
 
..and for bulk data you can go with:
excelSheet.get_Range("A1:H25", Type.Missing).Value2 =
    bidimensionalObjectArray;
  Permalink  
v3
Rate this: bad
good
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" />
            <Columns>
                <asp:TemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="ID">
                    <ItemTemplate >
                        <asp:Label ID="lblId" runat="server" Text='<%# Eval("ID")%>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" Width="15%" />
                </asp:TemplateColumn>
 
            <asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderText="Name">
                    <ItemTemplate>
                        <asp:Label ID="lblName" Text='<%# Eval("Name")%>' runat="server"></asp:Label>
                    </ItemTemplate>mn
                    <ItemStyle HorizontalAlign="Center" Width="20%" />
                </asp:TemplateColumn>
 
</Columns>
 
</asp:DataGrid>
In .cs page
               myGridView.DataSource = dd.tables[0];
                myGridView.DataBind();
                ExportToExcel(myGridView);
 

 
               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.
                myCtl.RenderControl(htw);
                HttpContext.Current.Response.Write(sw.ToString());
                HttpContext.Current.Response.End();
            }            
        }
 

Keep smiling Smile | :) Smile | :) Smile | :) Happy codingSmile | :)
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  

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

  Print Answers RSS
0 Schatak 394
1 OriginalGriff 355
2 Sergey Alexandrovich Kryukov 119
3 _Amy 115
4 Rob Philpott 100
0 OriginalGriff 7,097
1 Sergey Alexandrovich Kryukov 5,623
2 Maciej Los 3,504
3 Peter Leow 3,373
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
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