Problem with export to excel column format

Discussion in 'ASP .Net' started by CDonlan, Jun 19, 2007.

  1. CDonlan

    CDonlan Guest

    Here is how im exporting
    Code:
     //Clear response content and headers
                response.Clear();
                response.ClearContent();
                response.ClearHeaders();
    
                //Add header
                response.AddHeader("content-disposition",
    "attachment;filename=" + fileName + ".xls");
    
                response.Charset = string.Empty;
                response.Cache.SetCacheability(HttpCacheability.Public);
                response.ContentType = "application/vnd.ms-excel";
    
                //Create StringWriter
                StringWriter stringWrite = new StringWriter();
    
                //Create HtmlTextWriter
                HtmlTextWriter htmlWrite = new
    HtmlTextWriter(stringWrite);
    
                //Remove controls from Column Headers
                if (grdView.HeaderRow != null && grdView.HeaderRow.Cells !
    = null)
                {
                    for (int ct = 0; ct < grdView.HeaderRow.Cells.Count; ct
    ++)
                    {
                        //Save header text if found
                        string headerText =
    grdView.HeaderRow.Cells[ct].Text;
    
                        //Check for controls in header
                        if (grdView.HeaderRow.Cells[ct].HasControls())
                        {
                            //Check for link buttons (used in sorting)
                            if
    (grdView.HeaderRow.Cells[ct].Controls[0].GetType().ToString() ==
    "System.Web.UI.WebControls.DataControlLinkButton")
                            {
                                //Link button found, get text
                                headerText =
    ((LinkButton)grdView.HeaderRow.Cells[ct].Controls[0]).Text;
                            }
                            //Remove controls from header
                            grdView.HeaderRow.Cells[ct].Controls.Clear();
                        }
    
                        //Reassign header text
                        grdView.HeaderRow.Cells[ct].Text = headerText;
                    }
                }
    
                //Remove unwanted columns (header text listed in
    removeColumnList arraylist)
                if (excludedColumnList != null)
                {
                    foreach (DataControlField field in grdView.Columns)
                    {
                        if (excludedColumnList.Contains(field.HeaderText))
                        {
                            field.Visible = false;
                        }
                    }
                }
    
                //Call GridView's RenderControl method
                grdView.RenderControl(htmlWrite);
    
                //Add style to ensure that numeric data treated as text
    will retain the leading zeros.
                string style = @"<style> .zeroLeftPad { mso-number-format:
    \@; } </style> ";
                response.Write(style);
    
                //Write Response to browser
                response.Write(stringWrite.ToString());
    
                response.End();
    
    I have a bound field thats of type string. It can be a combination of
    letters and number. When ever that string is 1-1 ,2-3, 3-4, etc.. It
    converts that to a date , like 1-Jan. Is there a way to prevent this?
    Thanks.
     
    CDonlan, Jun 19, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2aWQgVmFsbGU=?=

    Invalid export DLL or export format

    =?Utf-8?B?RGF2aWQgVmFsbGU=?=, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,626
    =?Utf-8?B?RGF2aWQgVmFsbGU=?=
    Oct 29, 2003
  2. Peter
    Replies:
    1
    Views:
    10,067
    Steve C. Orr [MVP, MCSD]
    Nov 9, 2004
  3. Julien
    Replies:
    1
    Views:
    13,839
    Steve C. Orr [MVP, MCSD]
    Feb 28, 2005
  4. Alessandro

    Problem to Export in Excel data format

    Alessandro, Jun 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    591
    Alessandro
    Jun 9, 2005
  5. Lester  Mosley

    Change column width during Excel export

    Lester Mosley, Mar 25, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    9,487
Loading...

Share This Page